diff --git a/cmd/stdiscosrv/main.go b/cmd/stdiscosrv/main.go index eafa1dda9..8ef7ace17 100644 --- a/cmd/stdiscosrv/main.go +++ b/cmd/stdiscosrv/main.go @@ -88,11 +88,6 @@ var ( ) func main() { - const ( - cleanIntv = 1 * time.Hour - statsIntv = 5 * time.Minute - ) - var listen string var dir string var metricsListen string diff --git a/cmd/stindex/idxck.go b/cmd/stindex/idxck.go index 974dd6cbd..88d5b2eb5 100644 --- a/cmd/stindex/idxck.go +++ b/cmd/stindex/idxck.go @@ -167,8 +167,8 @@ func idxck(ldb *db.Lowlevel) (success bool) { if needsLocally(vl) { _, ok := needs[gk] if !ok { - dev, _ := deviceToIDs[string(vl.Versions[0].Device)] - fi, _ := fileInfos[fileInfoKey{gk.folder, dev, gk.name}] + dev := deviceToIDs[string(vl.Versions[0].Device)] + fi := fileInfos[fileInfoKey{gk.folder, dev, gk.name}] if !fi.IsDeleted() && !fi.IsIgnored() { fmt.Printf("Missing need entry for needed file %q, folder %q\n", gk.name, folder) } diff --git a/cmd/strelaypoolsrv/stats.go b/cmd/strelaypoolsrv/stats.go index 068b77335..ae4a8a751 100644 --- a/cmd/strelaypoolsrv/stats.go +++ b/cmd/strelaypoolsrv/stats.go @@ -126,7 +126,7 @@ func refreshStats() { go func(rel *relay) { t0 := time.Now() stats := fetchStats(rel) - duration := time.Now().Sub(t0).Seconds() + duration := time.Since(t0).Seconds() result := "success" if stats == nil { result = "failed" diff --git a/cmd/strelaysrv/session.go b/cmd/strelaysrv/session.go index cf381e340..0221434bd 100644 --- a/cmd/strelaysrv/session.go +++ b/cmd/strelaysrv/session.go @@ -22,7 +22,7 @@ import ( var ( sessionMut = sync.RWMutex{} activeSessions = make([]*session, 0) - pendingSessions = make(map[string]*session, 0) + pendingSessions = make(map[string]*session) numProxies int64 bytesProxied int64 ) diff --git a/cmd/syncthing/auditservice_test.go b/cmd/syncthing/auditservice_test.go index f3951f5e0..fcdae4d4f 100644 --- a/cmd/syncthing/auditservice_test.go +++ b/cmd/syncthing/auditservice_test.go @@ -37,7 +37,7 @@ func TestAuditService(t *testing.T) { // This event should not be logged, since we have stopped. events.Default.Log(events.ConfigSaved, "the third event") - result := string(buf.Bytes()) + result := buf.String() t.Log(result) if strings.Contains(result, "first event") { diff --git a/cmd/syncthing/gui.go b/cmd/syncthing/gui.go index 6c40b8ceb..0b3ffe118 100644 --- a/cmd/syncthing/gui.go +++ b/cmd/syncthing/gui.go @@ -531,7 +531,6 @@ func corsMiddleware(next http.Handler, allowFrameLoading bool) http.Handler { // For everything else, pass to the next handler next.ServeHTTP(w, r) - return }) } diff --git a/cmd/syncthing/locations.go b/cmd/syncthing/locations.go index 916d9d126..94a329471 100644 --- a/cmd/syncthing/locations.go +++ b/cmd/syncthing/locations.go @@ -22,17 +22,17 @@ type locationEnum string // more meaningful. const ( locConfigFile locationEnum = "config" - locCertFile = "certFile" - locKeyFile = "keyFile" - locHTTPSCertFile = "httpsCertFile" - locHTTPSKeyFile = "httpsKeyFile" - locDatabase = "database" - locLogFile = "logFile" - locCsrfTokens = "csrfTokens" - locPanicLog = "panicLog" - locAuditLog = "auditLog" - locGUIAssets = "GUIAssets" - locDefFolder = "defFolder" + locCertFile locationEnum = "certFile" + locKeyFile locationEnum = "keyFile" + locHTTPSCertFile locationEnum = "httpsCertFile" + locHTTPSKeyFile locationEnum = "httpsKeyFile" + locDatabase locationEnum = "database" + locLogFile locationEnum = "logFile" + locCsrfTokens locationEnum = "csrfTokens" + locPanicLog locationEnum = "panicLog" + locAuditLog locationEnum = "auditLog" + locGUIAssets locationEnum = "GUIAssets" + locDefFolder locationEnum = "defFolder" ) // Platform dependent directories diff --git a/cmd/syncthing/usage_report.go b/cmd/syncthing/usage_report.go index e9d2059f0..be7ca2eed 100644 --- a/cmd/syncthing/usage_report.go +++ b/cmd/syncthing/usage_report.go @@ -190,7 +190,7 @@ func reportData(cfg configIntf, m modelIntf, connectionsService connectionsIntf, res["upgradeAllowedPre"] = !(upgrade.DisabledByCompilation || noUpgradeFromEnv) && opts.AutoUpgradeIntervalH > 0 && opts.UpgradeToPreReleases if version >= 3 { - res["uptime"] = int(time.Now().Sub(startTime).Seconds()) + res["uptime"] = int(time.Since(startTime).Seconds()) res["natType"] = connectionsService.NATType() res["alwaysLocalNets"] = len(opts.AlwaysLocalNets) > 0 res["cacheIgnoredFiles"] = opts.CacheIgnoredFiles diff --git a/lib/connections/service.go b/lib/connections/service.go index aac8df980..9c192ca21 100644 --- a/lib/connections/service.go +++ b/lib/connections/service.go @@ -35,8 +35,8 @@ import ( ) var ( - dialers = make(map[string]dialerFactory, 0) - listeners = make(map[string]listenerFactory, 0) + dialers = make(map[string]dialerFactory) + listeners = make(map[string]listenerFactory) ) var ( diff --git a/lib/db/set_test.go b/lib/db/set_test.go index 2abc32966..8f4ce711d 100644 --- a/lib/db/set_test.go +++ b/lib/db/set_test.go @@ -418,10 +418,7 @@ func TestUpdateToInvalid(t *testing.T) { }) if !f.Iterate([]string{folder}, localHave[4].Blocks[0].Hash, func(folder, file string, index int32) bool { - if file == localHave[4].Name { - return true - } - return false + return file == localHave[4].Name }) { t.Errorf("First block of un-invalidated file is missing from blockmap") } diff --git a/lib/fs/basicfs_test.go b/lib/fs/basicfs_test.go index 08e501eab..88e9ce826 100644 --- a/lib/fs/basicfs_test.go +++ b/lib/fs/basicfs_test.go @@ -82,7 +82,7 @@ func TestChownFile(t *testing.T) { } fd.Close() - info, err := fs.Lstat("file") + _, err = fs.Lstat("file") if err != nil { t.Error("Unexpected error:", err) } @@ -94,7 +94,7 @@ func TestChownFile(t *testing.T) { t.Error("Unexpected error:", err) } - info, err = fs.Lstat("file") + info, err := fs.Lstat("file") if err != nil { t.Error("Unexpected error:", err) } diff --git a/lib/fs/fakefs.go b/lib/fs/fakefs.go index e19b76de5..986f9585b 100644 --- a/lib/fs/fakefs.go +++ b/lib/fs/fakefs.go @@ -500,7 +500,7 @@ func (fs *fakefs) URI() string { } func (fs *fakefs) SameFile(fi1, fi2 FileInfo) bool { - return fi1.Name() == fi1.Name() + return fi1.Name() == fi2.Name() } // fakeFile is the representation of an open file. We don't care if it's diff --git a/lib/fs/fakefs_test.go b/lib/fs/fakefs_test.go index 52e683dd4..a42dc592e 100644 --- a/lib/fs/fakefs_test.go +++ b/lib/fs/fakefs_test.go @@ -8,8 +8,8 @@ package fs import ( "bytes" + "io" "io/ioutil" - "os" "testing" ) @@ -23,7 +23,7 @@ func TestFakeFS(t *testing.T) { if err != nil { t.Fatal(err) } - info, err := fs.Stat("dira/dirb") + _, err = fs.Stat("dira/dirb") if err != nil { t.Fatal(err) } @@ -33,7 +33,7 @@ func TestFakeFS(t *testing.T) { if err != nil { t.Fatal(err) } - info, err = fs.Stat("dira/dirb/dirc") + _, err = fs.Stat("dira/dirb/dirc") if err != nil { t.Fatal(err) } @@ -51,7 +51,7 @@ func TestFakeFS(t *testing.T) { } // Stat on fd - info, err = fd.Stat() + info, err := fd.Stat() if err != nil { t.Fatal(err) } @@ -75,7 +75,7 @@ func TestFakeFS(t *testing.T) { } // Seek - _, err = fd.Seek(1, os.SEEK_SET) + _, err = fd.Seek(1, io.SeekStart) if err != nil { t.Fatal(err) } @@ -90,7 +90,7 @@ func TestFakeFS(t *testing.T) { } // Read again, same data hopefully - _, err = fd.Seek(0, os.SEEK_SET) + _, err = fd.Seek(0, io.SeekStart) if err != nil { t.Fatal(err) } @@ -133,7 +133,7 @@ func TestFakeFSRead(t *testing.T) { _ = fd.Truncate(3 * 1 << randomBlockShift) // Read - _, _ = fd.Seek(0, 0) + _, _ = fd.Seek(0, io.SeekStart) bs0, err := ioutil.ReadAll(fd) if err != nil { t.Fatal(err) @@ -143,7 +143,7 @@ func TestFakeFSRead(t *testing.T) { } // Read again, starting at an odd offset - _, _ = fd.Seek(0, 0) + _, _ = fd.Seek(0, io.SeekStart) buf0 := make([]byte, 12345) n, _ := fd.Read(buf0) if n != len(buf0) { diff --git a/lib/ignore/ignore_test.go b/lib/ignore/ignore_test.go index f2c27d28a..e7254a90e 100644 --- a/lib/ignore/ignore_test.go +++ b/lib/ignore/ignore_test.go @@ -9,6 +9,7 @@ package ignore import ( "bytes" "fmt" + "io" "io/ioutil" "os" "path/filepath" @@ -507,7 +508,7 @@ func TestCacheReload(t *testing.T) { if err != nil { t.Fatal(err) } - _, err = fd.Seek(0, os.SEEK_SET) + _, err = fd.Seek(0, io.SeekStart) if err != nil { t.Fatal(err) } diff --git a/lib/model/model.go b/lib/model/model.go index 4b54e3517..78808e908 100644 --- a/lib/model/model.go +++ b/lib/model/model.go @@ -115,7 +115,7 @@ type Model struct { type folderFactory func(*Model, config.FolderConfiguration, versioner.Versioner, fs.Filesystem) service var ( - folderFactories = make(map[config.FolderType]folderFactory, 0) + folderFactories = make(map[config.FolderType]folderFactory) ) var ( @@ -489,12 +489,8 @@ func (m *Model) UsageReportingStats(version int, preview bool) map[string]interf } // Noops, remove - if strings.HasSuffix(line, "**") { - line = line[:len(line)-2] - } - if strings.HasPrefix(line, "**/") { - line = line[3:] - } + line = strings.TrimSuffix(line, "**") + line = strings.TrimPrefix(line, "**/") if strings.HasPrefix(line, "/") { ignoreStats["rooted"] += 1 @@ -508,7 +504,7 @@ func (m *Model) UsageReportingStats(version int, preview bool) map[string]interf if strings.Contains(line, "**") { ignoreStats["doubleStars"] += 1 // Remove not to trip up star checks. - strings.Replace(line, "**", "", -1) + line = strings.Replace(line, "**", "", -1) } if strings.Contains(line, "*") { @@ -2392,6 +2388,11 @@ func (m *Model) GetFolderVersions(folder string) (map[string][]versioner.FileVer return nil } + // Skip walking if we cannot walk... + if err != nil { + return err + } + // Ignore symlinks if f.IsSymlink() { return fs.SkipDir diff --git a/lib/model/model_test.go b/lib/model/model_test.go index 076ab6266..9787b4494 100644 --- a/lib/model/model_test.go +++ b/lib/model/model_test.go @@ -2572,7 +2572,7 @@ func TestIssue2782(t *testing.T) { } m.fmut.Lock() - runner, _ := m.folderRunners["default"] + runner := m.folderRunners["default"] m.fmut.Unlock() if err := runner.CheckHealth(); err != nil { t.Error("health check error:", err) diff --git a/lib/model/progressemitter.go b/lib/model/progressemitter.go index a06487a48..55f3467a9 100644 --- a/lib/model/progressemitter.go +++ b/lib/model/progressemitter.go @@ -167,13 +167,14 @@ func (t *ProgressEmitter) sendDownloadProgressMessages() { // If we fail to find that folder, we tell the state to forget about it // and return us a list of updates which would clean up the state // on the remote end. - updates := state.cleanup(folder) - if len(updates) > 0 { - // XXX: Don't send this now, as the only way we've unshared a folder - // is by breaking the connection and reconnecting, hence sending - // forget messages for some random folder currently makes no sense. - // deviceConns[id].DownloadProgress(folder, updates, 0, nil) - } + state.cleanup(folder) + // updates := state.cleanup(folder) + // if len(updates) > 0 { + // XXX: Don't send this now, as the only way we've unshared a folder + // is by breaking the connection and reconnecting, hence sending + // forget messages for some random folder currently makes no sense. + // deviceConns[id].DownloadProgress(folder, updates, 0, nil) + // } } } } diff --git a/lib/model/progressemitter_test.go b/lib/model/progressemitter_test.go index 73947bee2..ff26dc509 100644 --- a/lib/model/progressemitter_test.go +++ b/lib/model/progressemitter_test.go @@ -193,7 +193,7 @@ func TestSendDownloadProgressMessages(t *testing.T) { v2 := (protocol.Vector{}).Update(1) // Requires more than 10 blocks to work. - blocks := make([]protocol.BlockInfo, 11, 11) + blocks := make([]protocol.BlockInfo, 11) state1 := &sharedPullerState{ folder: "folder", diff --git a/lib/model/requests_test.go b/lib/model/requests_test.go index ea8515bf5..2c27e9172 100644 --- a/lib/model/requests_test.go +++ b/lib/model/requests_test.go @@ -471,7 +471,6 @@ func TestIssue4841(t *testing.T) { t.Fatalf(`Sent index with file %v, should be "foo"`, fs[0].Name) } received <- fs[0] - return } fc.mut.Unlock() @@ -521,7 +520,6 @@ func TestRescanIfHaveInvalidContent(t *testing.T) { t.Fatalf(`Sent index with file %v, should be "foo"`, fs[0].Name) } received <- fs[0] - return } fc.mut.Unlock() @@ -551,7 +549,7 @@ func TestRescanIfHaveInvalidContent(t *testing.T) { t.Fatal(err) } - res, err = m.Request(device2, "default", "foo", int32(len(payload)), 0, f.Blocks[0].Hash, f.Blocks[0].WeakHash, false) + _, err = m.Request(device2, "default", "foo", int32(len(payload)), 0, f.Blocks[0].Hash, f.Blocks[0].WeakHash, false) if err == nil { t.Fatalf("expected failure") } @@ -586,7 +584,6 @@ func TestParentDeletion(t *testing.T) { fc.mut.Lock() fc.indexFn = func(folder string, fs []protocol.FileInfo) { received <- fs - return } fc.mut.Unlock() fc.sendIndexUpdate() diff --git a/lib/watchaggregator/aggregator_test.go b/lib/watchaggregator/aggregator_test.go index 5815cbfbc..30df4353e 100644 --- a/lib/watchaggregator/aggregator_test.go +++ b/lib/watchaggregator/aggregator_test.go @@ -231,9 +231,7 @@ func TestNoDelay(t *testing.T) { func getEventPaths(dir *eventDir, dirPath string, a *aggregator) []string { var paths []string for childName, childDir := range dir.dirs { - for _, path := range getEventPaths(childDir, filepath.Join(dirPath, childName), a) { - paths = append(paths, path) - } + paths = append(paths, getEventPaths(childDir, filepath.Join(dirPath, childName), a)...) } for name := range dir.events { paths = append(paths, filepath.Join(dirPath, name)) @@ -264,9 +262,7 @@ func compareBatchToExpected(batch []string, expectedPaths []string) (missing []s missing = append(missing, expected) } } - for _, received := range batch { - unexpected = append(unexpected, received) - } + unexpected = append(unexpected, batch...) return missing, unexpected }