diff --git a/.travis.yml b/.travis.yml index c69460b5..4aca423b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,18 +1,28 @@ language: go -matrix: - include: - - go: "1.10.x" - - go: "1.11.x" - - go: "1.12.x" - - go: "1.13.x" +os: + - linux + - osx + - windows + +go: + - "1.10.x" + - "1.11.x" + - "1.12.x" + - "1.13.x" install: - go get -t ./... - - "curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin" -script: - - go test -race - - golangci-lint run +before_script: + - | + if [[ $TRAVIS_GO_VERSION == '1.13.x' && $TRAVIS_OS_NAME == 'linux' ]]; then + curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin + fi -script: go test -v ./... +script: + - go test -v -race ./... + - | + if [[ $TRAVIS_GO_VERSION == '1.13.x' && $TRAVIS_OS_NAME == 'linux' ]]; then + golangci-lint run + fi diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fd1444e..73c884f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # CHANGELOG +## 4.0.5 + +* Ignore errors when syncing file system. These errors were primarily due + to the file system not supporting the sync call. Reported by devkappa. + GitHub #37. +* Use CRLF line endings on Windows for text files. +* Fix tests on Windows. + ## 4.0.4 (2019-08-30) * Do not try to sync the database directory when running on Windows. diff --git a/Makefile b/Makefile index f398383f..99af8c45 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,10 @@ DATADIR=/usr/local/share/GeoIP endif endif +ifeq ($(OS),Windows_NT) +MAYBE_CR=\r +endif + ifndef VERSION VERSION=unknown endif @@ -41,13 +45,13 @@ $(BUILDDIR)/geoipupdate: $(BUILDDIR) cp cmd/geoipupdate/geoipupdate $(BUILDDIR) $(BUILDDIR)/GeoIP.conf: $(BUILDDIR) conf/GeoIP.conf.default - sed -e 's|CONFFILE|$(CONFFILE)|g' -e 's|DATADIR|$(DATADIR)|g' conf/GeoIP.conf.default > $(BUILDDIR)/GeoIP.conf + sed -e 's|CONFFILE|$(CONFFILE)|g' -e 's|DATADIR|$(DATADIR)|g' -e 's|$$|$(MAYBE_CR)|g' conf/GeoIP.conf.default > $(BUILDDIR)/GeoIP.conf $(BUILDDIR)/GeoIP.conf.md: $(BUILDDIR) doc/GeoIP.conf.md - sed -e 's|CONFFILE|$(CONFFILE)|g' -e 's|DATADIR|$(DATADIR)|g' doc/GeoIP.conf.md > $(BUILDDIR)/GeoIP.conf.md + sed -e 's|CONFFILE|$(CONFFILE)|g' -e 's|DATADIR|$(DATADIR)|g' -e 's|$$|$(MAYBE_CR)|g' doc/GeoIP.conf.md > $(BUILDDIR)/GeoIP.conf.md $(BUILDDIR)/geoipupdate.md: $(BUILDDIR) doc/geoipupdate.md - sed -e 's|CONFFILE|$(CONFFILE)|g' -e 's|DATADIR|$(DATADIR)|g' doc/geoipupdate.md > $(BUILDDIR)/geoipupdate.md + sed -e 's|CONFFILE|$(CONFFILE)|g' -e 's|DATADIR|$(DATADIR)|g' -e 's|$$|$(MAYBE_CR)|g' doc/geoipupdate.md > $(BUILDDIR)/geoipupdate.md $(BUILDDIR)/GeoIP.conf.5: $(BUILDDIR)/GeoIP.conf.md $(BUILDDIR)/geoipupdate.md dev-bin/make-man-pages.pl "$(BUILDDIR)" diff --git a/cmd/geoipupdate/config.go b/cmd/geoipupdate/config.go index 7c9f75b9..00f10279 100644 --- a/cmd/geoipupdate/config.go +++ b/cmd/geoipupdate/config.go @@ -74,7 +74,7 @@ func NewConfig( // nolint: gocyclo keysSeen["AccountID"] = struct{}{} keysSeen["UserId"] = struct{}{} case "DatabaseDirectory": - config.DatabaseDirectory = value + config.DatabaseDirectory = filepath.Clean(value) case "EditionIDs", "ProductIds": config.EditionIDs = strings.Fields(value) keysSeen["EditionIDs"] = struct{}{} @@ -84,7 +84,7 @@ func NewConfig( // nolint: gocyclo case "LicenseKey": config.LicenseKey = value case "LockFile": - config.LockFile = value + config.LockFile = filepath.Clean(value) case "PreserveFileTimes": if value != "0" && value != "1" { return nil, errors.New("`PreserveFileTimes' must be 0 or 1") @@ -132,11 +132,11 @@ func NewConfig( // nolint: gocyclo // Argument takes precedence. if databaseDirectory != "" { - config.DatabaseDirectory = databaseDirectory + config.DatabaseDirectory = filepath.Clean(databaseDirectory) } if config.DatabaseDirectory == "" { - config.DatabaseDirectory = defaultDatabaseDirectory + config.DatabaseDirectory = filepath.Clean(defaultDatabaseDirectory) } if host == "" { diff --git a/cmd/geoipupdate/config_test.go b/cmd/geoipupdate/config_test.go index 102efbdb..da86b109 100644 --- a/cmd/geoipupdate/config_test.go +++ b/cmd/geoipupdate/config_test.go @@ -4,6 +4,7 @@ import ( "io/ioutil" "net/url" "os" + "path/filepath" "testing" "github.com/stretchr/testify/assert" @@ -60,9 +61,9 @@ EditionIDs GeoLite2-Country GeoLite2-City # LockFile DATADIR/.geoipupdate.lock `, Output: &Config{ - DatabaseDirectory: "/tmp", + DatabaseDirectory: filepath.Clean("/tmp"), EditionIDs: []string{"GeoLite2-Country", "GeoLite2-City"}, - LockFile: "/tmp/.geoipupdate.lock", + LockFile: filepath.Clean("/tmp/.geoipupdate.lock"), URL: "https://updates.maxmind.com", }, }, @@ -109,9 +110,9 @@ ProductIds GeoLite2-Country GeoLite2-City # LockFile DATADIR/.geoipupdate.lock `, Output: &Config{ - DatabaseDirectory: "/tmp", + DatabaseDirectory: filepath.Clean("/tmp"), EditionIDs: []string{"GeoLite2-Country", "GeoLite2-City"}, - LockFile: "/tmp/.geoipupdate.lock", + LockFile: filepath.Clean("/tmp/.geoipupdate.lock"), URL: "https://updates.maxmind.com", }, }, @@ -159,10 +160,10 @@ LockFile /usr/lock `, Output: &Config{ AccountID: 1234, - DatabaseDirectory: "/tmp", // Argument takes precedence + DatabaseDirectory: filepath.Clean("/tmp"), // Argument takes precedence EditionIDs: []string{"GeoLite2-Country", "GeoLite2-City", "GeoIP2-City"}, LicenseKey: "abcdefghi", - LockFile: "/usr/lock", + LockFile: filepath.Clean("/usr/lock"), Proxy: &url.URL{ Scheme: "http", User: url.UserPassword("username", "password"), @@ -237,9 +238,9 @@ EditionIDs GeoIP2-City`, LicenseKey 000000000000 EditionIDs GeoIP2-City`, Output: &Config{ - DatabaseDirectory: "/tmp", + DatabaseDirectory: filepath.Clean("/tmp"), EditionIDs: []string{"GeoIP2-City"}, - LockFile: "/tmp/.geoipupdate.lock", + LockFile: filepath.Clean("/tmp/.geoipupdate.lock"), URL: "https://updates.maxmind.com", }, }, @@ -249,9 +250,9 @@ EditionIDs GeoIP2-City`, LicenseKey 000000000000 EditionIDs GeoIP2-City`, Output: &Config{ - DatabaseDirectory: "/tmp", + DatabaseDirectory: filepath.Clean("/tmp"), EditionIDs: []string{"GeoIP2-City"}, - LockFile: "/tmp/.geoipupdate.lock", + LockFile: filepath.Clean("/tmp/.geoipupdate.lock"), URL: "https://updates.maxmind.com", }, }, @@ -262,10 +263,10 @@ LicenseKey abcd EditionIDs GeoIP2-City`, Output: &Config{ AccountID: 999999, - DatabaseDirectory: "/tmp", + DatabaseDirectory: filepath.Clean("/tmp"), EditionIDs: []string{"GeoIP2-City"}, LicenseKey: "abcd", - LockFile: "/tmp/.geoipupdate.lock", + LockFile: filepath.Clean("/tmp/.geoipupdate.lock"), URL: "https://updates.maxmind.com", }, }, @@ -280,10 +281,10 @@ SkipPeerVerification 1 `, Output: &Config{ AccountID: 123, - DatabaseDirectory: "/tmp", + DatabaseDirectory: filepath.Clean("/tmp"), EditionIDs: []string{"GeoIP2-City"}, LicenseKey: "abcd", - LockFile: "/tmp/.geoipupdate.lock", + LockFile: filepath.Clean("/tmp/.geoipupdate.lock"), URL: "https://updates.maxmind.com", }, }, @@ -292,10 +293,10 @@ SkipPeerVerification 1 Input: "AccountID 123\r\nLicenseKey 123\r\nEditionIDs GeoIP2-City\r\n", Output: &Config{ AccountID: 123, - DatabaseDirectory: "/tmp", + DatabaseDirectory: filepath.Clean("/tmp"), EditionIDs: []string{"GeoIP2-City"}, LicenseKey: "123", - LockFile: "/tmp/.geoipupdate.lock", + LockFile: filepath.Clean("/tmp/.geoipupdate.lock"), URL: "https://updates.maxmind.com", }, }, @@ -312,10 +313,10 @@ EditionIDs GeoLite2-City GeoLite2-Country `, Output: &Config{ AccountID: 123, - DatabaseDirectory: "/tmp", + DatabaseDirectory: filepath.Clean("/tmp"), EditionIDs: []string{"GeoLite2-City", "GeoLite2-Country"}, LicenseKey: "456", - LockFile: "/tmp/.geoipupdate.lock", + LockFile: filepath.Clean("/tmp/.geoipupdate.lock"), URL: "https://updates.maxmind.com", }, }, @@ -324,10 +325,10 @@ EditionIDs GeoLite2-City GeoLite2-Country Input: "AccountID\t123\nLicenseKey\t\t456\nEditionIDs\t\t\tGeoLite2-City\t\t\t\tGeoLite2-Country\t\t\t\t\n", Output: &Config{ AccountID: 123, - DatabaseDirectory: "/tmp", + DatabaseDirectory: filepath.Clean("/tmp"), EditionIDs: []string{"GeoLite2-City", "GeoLite2-Country"}, LicenseKey: "456", - LockFile: "/tmp/.geoipupdate.lock", + LockFile: filepath.Clean("/tmp/.geoipupdate.lock"), URL: "https://updates.maxmind.com", }, }, diff --git a/cmd/geoipupdate/main_test.go b/cmd/geoipupdate/main_test.go index a220a4a4..fe120e8e 100644 --- a/cmd/geoipupdate/main_test.go +++ b/cmd/geoipupdate/main_test.go @@ -131,7 +131,7 @@ func TestUpdateEdition(t *testing.T) { FilenameBody: "GeoIP2-City.mmdb", DownloadStatus: http.StatusOK, DownloadBody: "new database goes here", - Err: `error updating: error creating file: open \S+GeoIP2-City\.mmdb\.test: no such file or directory`, + Err: `error updating: error creating file: open \S+GeoIP2-City\.mmdb\.test: (?:no such file or directory|The system cannot find the path specified)`, }, { Description: "Download fails because provided checksum does not match",