all: A few more interesting linter fixes (#5502)

A couple of minor bugs and simplifications
This commit is contained in:
Jakob Borg 2019-02-02 12:09:07 +01:00 committed by GitHub
parent 0b2cabbc31
commit 9fd270d78e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 55 additions and 68 deletions

View File

@ -88,11 +88,6 @@ var (
) )
func main() { func main() {
const (
cleanIntv = 1 * time.Hour
statsIntv = 5 * time.Minute
)
var listen string var listen string
var dir string var dir string
var metricsListen string var metricsListen string

View File

@ -167,8 +167,8 @@ func idxck(ldb *db.Lowlevel) (success bool) {
if needsLocally(vl) { if needsLocally(vl) {
_, ok := needs[gk] _, ok := needs[gk]
if !ok { if !ok {
dev, _ := deviceToIDs[string(vl.Versions[0].Device)] dev := deviceToIDs[string(vl.Versions[0].Device)]
fi, _ := fileInfos[fileInfoKey{gk.folder, dev, gk.name}] fi := fileInfos[fileInfoKey{gk.folder, dev, gk.name}]
if !fi.IsDeleted() && !fi.IsIgnored() { if !fi.IsDeleted() && !fi.IsIgnored() {
fmt.Printf("Missing need entry for needed file %q, folder %q\n", gk.name, folder) fmt.Printf("Missing need entry for needed file %q, folder %q\n", gk.name, folder)
} }

View File

@ -126,7 +126,7 @@ func refreshStats() {
go func(rel *relay) { go func(rel *relay) {
t0 := time.Now() t0 := time.Now()
stats := fetchStats(rel) stats := fetchStats(rel)
duration := time.Now().Sub(t0).Seconds() duration := time.Since(t0).Seconds()
result := "success" result := "success"
if stats == nil { if stats == nil {
result = "failed" result = "failed"

View File

@ -22,7 +22,7 @@ import (
var ( var (
sessionMut = sync.RWMutex{} sessionMut = sync.RWMutex{}
activeSessions = make([]*session, 0) activeSessions = make([]*session, 0)
pendingSessions = make(map[string]*session, 0) pendingSessions = make(map[string]*session)
numProxies int64 numProxies int64
bytesProxied int64 bytesProxied int64
) )

View File

@ -37,7 +37,7 @@ func TestAuditService(t *testing.T) {
// This event should not be logged, since we have stopped. // This event should not be logged, since we have stopped.
events.Default.Log(events.ConfigSaved, "the third event") events.Default.Log(events.ConfigSaved, "the third event")
result := string(buf.Bytes()) result := buf.String()
t.Log(result) t.Log(result)
if strings.Contains(result, "first event") { if strings.Contains(result, "first event") {

View File

@ -531,7 +531,6 @@ func corsMiddleware(next http.Handler, allowFrameLoading bool) http.Handler {
// For everything else, pass to the next handler // For everything else, pass to the next handler
next.ServeHTTP(w, r) next.ServeHTTP(w, r)
return
}) })
} }

View File

@ -22,17 +22,17 @@ type locationEnum string
// more meaningful. // more meaningful.
const ( const (
locConfigFile locationEnum = "config" locConfigFile locationEnum = "config"
locCertFile = "certFile" locCertFile locationEnum = "certFile"
locKeyFile = "keyFile" locKeyFile locationEnum = "keyFile"
locHTTPSCertFile = "httpsCertFile" locHTTPSCertFile locationEnum = "httpsCertFile"
locHTTPSKeyFile = "httpsKeyFile" locHTTPSKeyFile locationEnum = "httpsKeyFile"
locDatabase = "database" locDatabase locationEnum = "database"
locLogFile = "logFile" locLogFile locationEnum = "logFile"
locCsrfTokens = "csrfTokens" locCsrfTokens locationEnum = "csrfTokens"
locPanicLog = "panicLog" locPanicLog locationEnum = "panicLog"
locAuditLog = "auditLog" locAuditLog locationEnum = "auditLog"
locGUIAssets = "GUIAssets" locGUIAssets locationEnum = "GUIAssets"
locDefFolder = "defFolder" locDefFolder locationEnum = "defFolder"
) )
// Platform dependent directories // Platform dependent directories

View File

@ -190,7 +190,7 @@ func reportData(cfg configIntf, m modelIntf, connectionsService connectionsIntf,
res["upgradeAllowedPre"] = !(upgrade.DisabledByCompilation || noUpgradeFromEnv) && opts.AutoUpgradeIntervalH > 0 && opts.UpgradeToPreReleases res["upgradeAllowedPre"] = !(upgrade.DisabledByCompilation || noUpgradeFromEnv) && opts.AutoUpgradeIntervalH > 0 && opts.UpgradeToPreReleases
if version >= 3 { if version >= 3 {
res["uptime"] = int(time.Now().Sub(startTime).Seconds()) res["uptime"] = int(time.Since(startTime).Seconds())
res["natType"] = connectionsService.NATType() res["natType"] = connectionsService.NATType()
res["alwaysLocalNets"] = len(opts.AlwaysLocalNets) > 0 res["alwaysLocalNets"] = len(opts.AlwaysLocalNets) > 0
res["cacheIgnoredFiles"] = opts.CacheIgnoredFiles res["cacheIgnoredFiles"] = opts.CacheIgnoredFiles

View File

@ -35,8 +35,8 @@ import (
) )
var ( var (
dialers = make(map[string]dialerFactory, 0) dialers = make(map[string]dialerFactory)
listeners = make(map[string]listenerFactory, 0) listeners = make(map[string]listenerFactory)
) )
var ( var (

View File

@ -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 !f.Iterate([]string{folder}, localHave[4].Blocks[0].Hash, func(folder, file string, index int32) bool {
if file == localHave[4].Name { return file == localHave[4].Name
return true
}
return false
}) { }) {
t.Errorf("First block of un-invalidated file is missing from blockmap") t.Errorf("First block of un-invalidated file is missing from blockmap")
} }

View File

@ -82,7 +82,7 @@ func TestChownFile(t *testing.T) {
} }
fd.Close() fd.Close()
info, err := fs.Lstat("file") _, err = fs.Lstat("file")
if err != nil { if err != nil {
t.Error("Unexpected error:", err) t.Error("Unexpected error:", err)
} }
@ -94,7 +94,7 @@ func TestChownFile(t *testing.T) {
t.Error("Unexpected error:", err) t.Error("Unexpected error:", err)
} }
info, err = fs.Lstat("file") info, err := fs.Lstat("file")
if err != nil { if err != nil {
t.Error("Unexpected error:", err) t.Error("Unexpected error:", err)
} }

View File

@ -500,7 +500,7 @@ func (fs *fakefs) URI() string {
} }
func (fs *fakefs) SameFile(fi1, fi2 FileInfo) bool { 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 // fakeFile is the representation of an open file. We don't care if it's

View File

@ -8,8 +8,8 @@ package fs
import ( import (
"bytes" "bytes"
"io"
"io/ioutil" "io/ioutil"
"os"
"testing" "testing"
) )
@ -23,7 +23,7 @@ func TestFakeFS(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
info, err := fs.Stat("dira/dirb") _, err = fs.Stat("dira/dirb")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -33,7 +33,7 @@ func TestFakeFS(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
info, err = fs.Stat("dira/dirb/dirc") _, err = fs.Stat("dira/dirb/dirc")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -51,7 +51,7 @@ func TestFakeFS(t *testing.T) {
} }
// Stat on fd // Stat on fd
info, err = fd.Stat() info, err := fd.Stat()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -75,7 +75,7 @@ func TestFakeFS(t *testing.T) {
} }
// Seek // Seek
_, err = fd.Seek(1, os.SEEK_SET) _, err = fd.Seek(1, io.SeekStart)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -90,7 +90,7 @@ func TestFakeFS(t *testing.T) {
} }
// Read again, same data hopefully // Read again, same data hopefully
_, err = fd.Seek(0, os.SEEK_SET) _, err = fd.Seek(0, io.SeekStart)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -133,7 +133,7 @@ func TestFakeFSRead(t *testing.T) {
_ = fd.Truncate(3 * 1 << randomBlockShift) _ = fd.Truncate(3 * 1 << randomBlockShift)
// Read // Read
_, _ = fd.Seek(0, 0) _, _ = fd.Seek(0, io.SeekStart)
bs0, err := ioutil.ReadAll(fd) bs0, err := ioutil.ReadAll(fd)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -143,7 +143,7 @@ func TestFakeFSRead(t *testing.T) {
} }
// Read again, starting at an odd offset // Read again, starting at an odd offset
_, _ = fd.Seek(0, 0) _, _ = fd.Seek(0, io.SeekStart)
buf0 := make([]byte, 12345) buf0 := make([]byte, 12345)
n, _ := fd.Read(buf0) n, _ := fd.Read(buf0)
if n != len(buf0) { if n != len(buf0) {

View File

@ -9,6 +9,7 @@ package ignore
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
@ -507,7 +508,7 @@ func TestCacheReload(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
_, err = fd.Seek(0, os.SEEK_SET) _, err = fd.Seek(0, io.SeekStart)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -115,7 +115,7 @@ type Model struct {
type folderFactory func(*Model, config.FolderConfiguration, versioner.Versioner, fs.Filesystem) service type folderFactory func(*Model, config.FolderConfiguration, versioner.Versioner, fs.Filesystem) service
var ( var (
folderFactories = make(map[config.FolderType]folderFactory, 0) folderFactories = make(map[config.FolderType]folderFactory)
) )
var ( var (
@ -489,12 +489,8 @@ func (m *Model) UsageReportingStats(version int, preview bool) map[string]interf
} }
// Noops, remove // Noops, remove
if strings.HasSuffix(line, "**") { line = strings.TrimSuffix(line, "**")
line = line[:len(line)-2] line = strings.TrimPrefix(line, "**/")
}
if strings.HasPrefix(line, "**/") {
line = line[3:]
}
if strings.HasPrefix(line, "/") { if strings.HasPrefix(line, "/") {
ignoreStats["rooted"] += 1 ignoreStats["rooted"] += 1
@ -508,7 +504,7 @@ func (m *Model) UsageReportingStats(version int, preview bool) map[string]interf
if strings.Contains(line, "**") { if strings.Contains(line, "**") {
ignoreStats["doubleStars"] += 1 ignoreStats["doubleStars"] += 1
// Remove not to trip up star checks. // Remove not to trip up star checks.
strings.Replace(line, "**", "", -1) line = strings.Replace(line, "**", "", -1)
} }
if strings.Contains(line, "*") { if strings.Contains(line, "*") {
@ -2392,6 +2388,11 @@ func (m *Model) GetFolderVersions(folder string) (map[string][]versioner.FileVer
return nil return nil
} }
// Skip walking if we cannot walk...
if err != nil {
return err
}
// Ignore symlinks // Ignore symlinks
if f.IsSymlink() { if f.IsSymlink() {
return fs.SkipDir return fs.SkipDir

View File

@ -2572,7 +2572,7 @@ func TestIssue2782(t *testing.T) {
} }
m.fmut.Lock() m.fmut.Lock()
runner, _ := m.folderRunners["default"] runner := m.folderRunners["default"]
m.fmut.Unlock() m.fmut.Unlock()
if err := runner.CheckHealth(); err != nil { if err := runner.CheckHealth(); err != nil {
t.Error("health check error:", err) t.Error("health check error:", err)

View File

@ -167,13 +167,14 @@ func (t *ProgressEmitter) sendDownloadProgressMessages() {
// If we fail to find that folder, we tell the state to forget about it // 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 // and return us a list of updates which would clean up the state
// on the remote end. // on the remote end.
updates := state.cleanup(folder) state.cleanup(folder)
if len(updates) > 0 { // updates := state.cleanup(folder)
// XXX: Don't send this now, as the only way we've unshared a folder // if len(updates) > 0 {
// is by breaking the connection and reconnecting, hence sending // XXX: Don't send this now, as the only way we've unshared a folder
// forget messages for some random folder currently makes no sense. // is by breaking the connection and reconnecting, hence sending
// deviceConns[id].DownloadProgress(folder, updates, 0, nil) // forget messages for some random folder currently makes no sense.
} // deviceConns[id].DownloadProgress(folder, updates, 0, nil)
// }
} }
} }
} }

View File

@ -193,7 +193,7 @@ func TestSendDownloadProgressMessages(t *testing.T) {
v2 := (protocol.Vector{}).Update(1) v2 := (protocol.Vector{}).Update(1)
// Requires more than 10 blocks to work. // Requires more than 10 blocks to work.
blocks := make([]protocol.BlockInfo, 11, 11) blocks := make([]protocol.BlockInfo, 11)
state1 := &sharedPullerState{ state1 := &sharedPullerState{
folder: "folder", folder: "folder",

View File

@ -471,7 +471,6 @@ func TestIssue4841(t *testing.T) {
t.Fatalf(`Sent index with file %v, should be "foo"`, fs[0].Name) t.Fatalf(`Sent index with file %v, should be "foo"`, fs[0].Name)
} }
received <- fs[0] received <- fs[0]
return
} }
fc.mut.Unlock() 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) t.Fatalf(`Sent index with file %v, should be "foo"`, fs[0].Name)
} }
received <- fs[0] received <- fs[0]
return
} }
fc.mut.Unlock() fc.mut.Unlock()
@ -551,7 +549,7 @@ func TestRescanIfHaveInvalidContent(t *testing.T) {
t.Fatal(err) 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 { if err == nil {
t.Fatalf("expected failure") t.Fatalf("expected failure")
} }
@ -586,7 +584,6 @@ func TestParentDeletion(t *testing.T) {
fc.mut.Lock() fc.mut.Lock()
fc.indexFn = func(folder string, fs []protocol.FileInfo) { fc.indexFn = func(folder string, fs []protocol.FileInfo) {
received <- fs received <- fs
return
} }
fc.mut.Unlock() fc.mut.Unlock()
fc.sendIndexUpdate() fc.sendIndexUpdate()

View File

@ -231,9 +231,7 @@ func TestNoDelay(t *testing.T) {
func getEventPaths(dir *eventDir, dirPath string, a *aggregator) []string { func getEventPaths(dir *eventDir, dirPath string, a *aggregator) []string {
var paths []string var paths []string
for childName, childDir := range dir.dirs { for childName, childDir := range dir.dirs {
for _, path := range getEventPaths(childDir, filepath.Join(dirPath, childName), a) { paths = append(paths, getEventPaths(childDir, filepath.Join(dirPath, childName), a)...)
paths = append(paths, path)
}
} }
for name := range dir.events { for name := range dir.events {
paths = append(paths, filepath.Join(dirPath, name)) paths = append(paths, filepath.Join(dirPath, name))
@ -264,9 +262,7 @@ func compareBatchToExpected(batch []string, expectedPaths []string) (missing []s
missing = append(missing, expected) missing = append(missing, expected)
} }
} }
for _, received := range batch { unexpected = append(unexpected, batch...)
unexpected = append(unexpected, received)
}
return missing, unexpected return missing, unexpected
} }