mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-22 19:08:58 +00:00
all: A few more interesting linter fixes (#5502)
A couple of minor bugs and simplifications
This commit is contained in:
parent
0b2cabbc31
commit
9fd270d78e
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
)
|
||||
|
@ -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") {
|
||||
|
@ -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
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 (
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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",
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user