all: Fix some linter errors (#5499)

I'm working through linter complaints, these are some fixes. Broad
categories:

1) Ignore errors where we can ignore errors: add "_ = ..." construct.
you can argue that this is annoying noise, but apart from silencing the
linter it *does* serve the purpose of highlighting that an error is
being ignored. I think this is OK, because the linter highlighted some
error cases I wasn't aware of (starting CPU profiles, for example).

2) Untyped constants where we though we had set the type.

3) A real bug where we ineffectually assigned to a shadowed err.

4) Some dead code removed.

There'll be more of these, because not all packages are fixed, but the
diff was already large enough.
This commit is contained in:
Jakob Borg 2019-02-02 10:11:42 +01:00 committed by GitHub
parent 583172dc8d
commit 2111386ee4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 103 additions and 107 deletions

View File

@ -44,7 +44,7 @@ func (s *auditService) Serve() {
for { for {
select { select {
case ev := <-sub.C(): case ev := <-sub.C():
enc.Encode(ev) _ = enc.Encode(ev)
case <-s.stop: case <-s.stop:
return return
} }

View File

@ -13,6 +13,6 @@ import "time"
func cpuUsage() time.Duration { func cpuUsage() time.Duration {
var rusage syscall.Rusage var rusage syscall.Rusage
syscall.Getrusage(syscall.RUSAGE_SELF, &rusage) _ = syscall.Getrusage(syscall.RUSAGE_SELF, &rusage)
return time.Duration(rusage.Utime.Nano() + rusage.Stime.Nano()) return time.Duration(rusage.Utime.Nano() + rusage.Stime.Nano())
} }

View File

@ -27,7 +27,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/rcrowley/go-metrics" metrics "github.com/rcrowley/go-metrics"
"github.com/syncthing/syncthing/lib/config" "github.com/syncthing/syncthing/lib/config"
"github.com/syncthing/syncthing/lib/connections" "github.com/syncthing/syncthing/lib/connections"
"github.com/syncthing/syncthing/lib/db" "github.com/syncthing/syncthing/lib/db"
@ -966,7 +966,7 @@ func (s *apiService) postSystemShutdown(w http.ResponseWriter, r *http.Request)
} }
func (s *apiService) flushResponse(resp string, w http.ResponseWriter) { func (s *apiService) flushResponse(resp string, w http.ResponseWriter) {
w.Write([]byte(resp + "\n")) _, _ = w.Write([]byte(resp + "\n"))
f := w.(http.Flusher) f := w.(http.Flusher)
f.Flush() f.Flush()
} }
@ -1121,15 +1121,17 @@ func (s *apiService) getSupportBundle(w http.ResponseWriter, r *http.Request) {
var heapBuffer, cpuBuffer bytes.Buffer var heapBuffer, cpuBuffer bytes.Buffer
filename := fmt.Sprintf("syncthing-heap-%s-%s-%s-%s.pprof", runtime.GOOS, runtime.GOARCH, Version, time.Now().Format("150405")) // hhmmss filename := fmt.Sprintf("syncthing-heap-%s-%s-%s-%s.pprof", runtime.GOOS, runtime.GOARCH, Version, time.Now().Format("150405")) // hhmmss
runtime.GC() runtime.GC()
pprof.WriteHeapProfile(&heapBuffer) if err := pprof.WriteHeapProfile(&heapBuffer); err == nil {
files = append(files, fileEntry{name: filename, data: heapBuffer.Bytes()}) files = append(files, fileEntry{name: filename, data: heapBuffer.Bytes()})
}
const duration = 4 * time.Second const duration = 4 * time.Second
filename = fmt.Sprintf("syncthing-cpu-%s-%s-%s-%s.pprof", runtime.GOOS, runtime.GOARCH, Version, time.Now().Format("150405")) // hhmmss filename = fmt.Sprintf("syncthing-cpu-%s-%s-%s-%s.pprof", runtime.GOOS, runtime.GOARCH, Version, time.Now().Format("150405")) // hhmmss
pprof.StartCPUProfile(&cpuBuffer) if err := pprof.StartCPUProfile(&cpuBuffer); err == nil {
time.Sleep(duration) time.Sleep(duration)
pprof.StopCPUProfile() pprof.StopCPUProfile()
files = append(files, fileEntry{name: filename, data: cpuBuffer.Bytes()}) files = append(files, fileEntry{name: filename, data: cpuBuffer.Bytes()})
}
// Add buffer files to buffer zip // Add buffer files to buffer zip
var zipFilesBuffer bytes.Buffer var zipFilesBuffer bytes.Buffer
@ -1151,7 +1153,7 @@ func (s *apiService) getSupportBundle(w http.ResponseWriter, r *http.Request) {
// Serve the buffer zip to client for download // Serve the buffer zip to client for download
w.Header().Set("Content-Type", "application/zip") w.Header().Set("Content-Type", "application/zip")
w.Header().Set("Content-Disposition", "attachment; filename="+zipFileName) w.Header().Set("Content-Disposition", "attachment; filename="+zipFileName)
io.Copy(w, &zipFilesBuffer) _, _ = io.Copy(w, &zipFilesBuffer)
} }
func (s *apiService) getSystemHTTPMetrics(w http.ResponseWriter, r *http.Request) { func (s *apiService) getSystemHTTPMetrics(w http.ResponseWriter, r *http.Request) {
@ -1171,7 +1173,7 @@ func (s *apiService) getSystemHTTPMetrics(w http.ResponseWriter, r *http.Request
} }
}) })
bs, _ := json.MarshalIndent(stats, "", " ") bs, _ := json.MarshalIndent(stats, "", " ")
w.Write(bs) _, _ = w.Write(bs)
} }
func (s *apiService) getSystemDiscovery(w http.ResponseWriter, r *http.Request) { func (s *apiService) getSystemDiscovery(w http.ResponseWriter, r *http.Request) {
@ -1463,7 +1465,7 @@ func (s *apiService) getQR(w http.ResponseWriter, r *http.Request) {
} }
w.Header().Set("Content-Type", "image/png") w.Header().Set("Content-Type", "image/png")
w.Write(code.PNG()) _, _ = w.Write(code.PNG())
} }
func (s *apiService) getPeerCompletion(w http.ResponseWriter, r *http.Request) { func (s *apiService) getPeerCompletion(w http.ResponseWriter, r *http.Request) {
@ -1561,7 +1563,7 @@ func (s *apiService) getSystemBrowse(w http.ResponseWriter, r *http.Request) {
// Default value or in case of error unmarshalling ends up being basic fs. // Default value or in case of error unmarshalling ends up being basic fs.
var fsType fs.FilesystemType var fsType fs.FilesystemType
fsType.UnmarshalText([]byte(qs.Get("filesystem"))) _ = fsType.UnmarshalText([]byte(qs.Get("filesystem")))
sendJSON(w, browseFiles(current, fsType)) sendJSON(w, browseFiles(current, fsType))
} }
@ -1645,9 +1647,10 @@ func (s *apiService) getCPUProf(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/octet-stream") w.Header().Set("Content-Type", "application/octet-stream")
w.Header().Set("Content-Disposition", "attachment; filename="+filename) w.Header().Set("Content-Disposition", "attachment; filename="+filename)
pprof.StartCPUProfile(w) if err := pprof.StartCPUProfile(w); err == nil {
time.Sleep(duration) time.Sleep(duration)
pprof.StopCPUProfile() pprof.StopCPUProfile()
}
} }
func (s *apiService) getHeapProf(w http.ResponseWriter, r *http.Request) { func (s *apiService) getHeapProf(w http.ResponseWriter, r *http.Request) {
@ -1657,7 +1660,7 @@ func (s *apiService) getHeapProf(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Disposition", "attachment; filename="+filename) w.Header().Set("Content-Disposition", "attachment; filename="+filename)
runtime.GC() runtime.GC()
pprof.WriteHeapProfile(w) _ = pprof.WriteHeapProfile(w)
} }
func toJsonFileInfoSlice(fs []db.FileInfoTruncated) []jsonDBFileInfo { func toJsonFileInfoSlice(fs []db.FileInfoTruncated) []jsonDBFileInfo {

View File

@ -20,7 +20,7 @@ import (
"github.com/syncthing/syncthing/lib/rand" "github.com/syncthing/syncthing/lib/rand"
"github.com/syncthing/syncthing/lib/sync" "github.com/syncthing/syncthing/lib/sync"
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"
"gopkg.in/ldap.v2" ldap "gopkg.in/ldap.v2"
) )
var ( var (
@ -80,11 +80,10 @@ func basicAuthAndSessionMiddleware(cookieName string, guiCfg config.GUIConfigura
return return
} }
authOk := false
username := string(fields[0]) username := string(fields[0])
password := string(fields[1]) password := string(fields[1])
authOk = auth(username, password, guiCfg, ldapCfg) authOk := auth(username, password, guiCfg, ldapCfg)
if !authOk { if !authOk {
usernameIso := string(iso88591ToUTF8([]byte(username))) usernameIso := string(iso88591ToUTF8([]byte(username)))
passwordIso := string(iso88591ToUTF8([]byte(password))) passwordIso := string(iso88591ToUTF8([]byte(password)))

View File

@ -160,7 +160,7 @@ func (s *staticsServer) serveAsset(w http.ResponseWriter, r *http.Request) {
} }
w.Header().Set("Content-Length", fmt.Sprintf("%d", len(bs))) w.Header().Set("Content-Length", fmt.Sprintf("%d", len(bs)))
w.Write(bs) _, _ = w.Write(bs)
} }
func (s *staticsServer) serveThemes(w http.ResponseWriter, r *http.Request) { func (s *staticsServer) serveThemes(w http.ResponseWriter, r *http.Request) {

View File

@ -114,13 +114,13 @@ func TestAssetsDir(t *testing.T) {
// The asset map contains compressed assets, so create a couple of gzip compressed assets here. // The asset map contains compressed assets, so create a couple of gzip compressed assets here.
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
gw := gzip.NewWriter(buf) gw := gzip.NewWriter(buf)
gw.Write([]byte("default")) _, _ = gw.Write([]byte("default"))
gw.Close() gw.Close()
def := buf.Bytes() def := buf.Bytes()
buf = new(bytes.Buffer) buf = new(bytes.Buffer)
gw = gzip.NewWriter(buf) gw = gzip.NewWriter(buf)
gw.Write([]byte("foo")) _, _ = gw.Write([]byte("foo"))
gw.Close() gw.Close()
foo := buf.Bytes() foo := buf.Bytes()

View File

@ -127,7 +127,6 @@ func setBuildMetadata() {
var ( var (
myID protocol.DeviceID myID protocol.DeviceID
stop = make(chan int) stop = make(chan int)
lans []*net.IPNet
) )
const ( const (
@ -436,7 +435,9 @@ func main() {
} }
if options.resetDatabase { if options.resetDatabase {
resetDB() if err := resetDB(); err != nil {
l.Fatalln("Resetting database:", err)
}
return return
} }
@ -450,7 +451,9 @@ func main() {
func openGUI() { func openGUI() {
cfg, _ := loadOrDefaultConfig() cfg, _ := loadOrDefaultConfig()
if cfg.GUI().Enabled { if cfg.GUI().Enabled {
openURL(cfg.GUI().URL()) if err := openURL(cfg.GUI().URL()); err != nil {
l.Fatalln("Open URL:", err)
}
} else { } else {
l.Warnln("Browser: GUI is currently disabled") l.Warnln("Browser: GUI is currently disabled")
} }
@ -631,7 +634,7 @@ func syncthingMain(runtimeOptions RuntimeOptions) {
// Attempt to increase the limit on number of open files to the maximum // Attempt to increase the limit on number of open files to the maximum
// allowed, in case we have many peers. We don't really care enough to // allowed, in case we have many peers. We don't really care enough to
// report the error if there is one. // report the error if there is one.
osutil.MaximizeOpenFileLimit() _, _ = osutil.MaximizeOpenFileLimit()
// Ensure that we have a certificate and key. // Ensure that we have a certificate and key.
cert, err := tls.LoadX509KeyPair(locations[locCertFile], locations[locKeyFile]) cert, err := tls.LoadX509KeyPair(locations[locCertFile], locations[locKeyFile])
@ -754,7 +757,7 @@ func syncthingMain(runtimeOptions RuntimeOptions) {
// Add and start folders // Add and start folders
for _, folderCfg := range cfg.Folders() { for _, folderCfg := range cfg.Folders() {
if folderCfg.Paused { if folderCfg.Paused {
folderCfg.CreateRoot() _ = folderCfg.CreateRoot()
continue continue
} }
m.AddFolder(folderCfg) m.AddFolder(folderCfg)
@ -823,9 +826,11 @@ func syncthingMain(runtimeOptions RuntimeOptions) {
if runtimeOptions.cpuProfile { if runtimeOptions.cpuProfile {
f, err := os.Create(fmt.Sprintf("cpu-%d.pprof", os.Getpid())) f, err := os.Create(fmt.Sprintf("cpu-%d.pprof", os.Getpid()))
if err != nil { if err != nil {
log.Fatal(err) l.Fatalln("Creating profile:", err)
}
if err := pprof.StartCPUProfile(f); err != nil {
l.Fatalln("Starting profile:", err)
} }
pprof.StartCPUProfile(f)
} }
myDev, _ := cfg.Device(myID) myDev, _ := cfg.Device(myID)
@ -842,8 +847,8 @@ func syncthingMain(runtimeOptions RuntimeOptions) {
l.Infoln("Anonymous usage reporting is always enabled for candidate releases.") l.Infoln("Anonymous usage reporting is always enabled for candidate releases.")
if opts.URAccepted != usageReportVersion { if opts.URAccepted != usageReportVersion {
opts.URAccepted = usageReportVersion opts.URAccepted = usageReportVersion
cfg.SetOptions(opts) _, _ = cfg.SetOptions(opts)
cfg.Save() _ = cfg.Save()
// Unique ID will be set and config saved below if necessary. // Unique ID will be set and config saved below if necessary.
} }
} }
@ -851,8 +856,8 @@ func syncthingMain(runtimeOptions RuntimeOptions) {
// If we are going to do usage reporting, ensure we have a valid unique ID. // If we are going to do usage reporting, ensure we have a valid unique ID.
if opts := cfg.Options(); opts.URAccepted > 0 && opts.URUniqueID == "" { if opts := cfg.Options(); opts.URAccepted > 0 && opts.URUniqueID == "" {
opts.URUniqueID = rand.String(8) opts.URUniqueID = rand.String(8)
cfg.SetOptions(opts) _, _ = cfg.SetOptions(opts)
cfg.Save() _ = cfg.Save()
} }
usageReportingSvc := newUsageReportingService(cfg, m, connectionsService) usageReportingSvc := newUsageReportingService(cfg, m, connectionsService)
@ -872,8 +877,8 @@ func syncthingMain(runtimeOptions RuntimeOptions) {
opts.AutoUpgradeIntervalH = 12 opts.AutoUpgradeIntervalH = 12
// Set the option into the config as well, as the auto upgrade // Set the option into the config as well, as the auto upgrade
// loop expects to read a valid interval from there. // loop expects to read a valid interval from there.
cfg.SetOptions(opts) _, _ = cfg.SetOptions(opts)
cfg.Save() _ = cfg.Save()
} }
// We don't tweak the user's choice of upgrading to pre-releases or // We don't tweak the user's choice of upgrading to pre-releases or
// not, as otherwise they cannot step off the candidate channel. // not, as otherwise they cannot step off the candidate channel.
@ -954,7 +959,7 @@ func loadConfigAtStartup() *config.Wrapper {
cfg, err := config.Load(cfgFile, myID) cfg, err := config.Load(cfgFile, myID)
if os.IsNotExist(err) { if os.IsNotExist(err) {
cfg = defaultConfig(cfgFile) cfg = defaultConfig(cfgFile)
cfg.Save() _ = cfg.Save()
l.Infof("Default config saved. Edit %s to taste or use the GUI\n", cfg.ConfigPath()) l.Infof("Default config saved. Edit %s to taste or use the GUI\n", cfg.ConfigPath())
} else if err == io.EOF { } else if err == io.EOF {
l.Fatalln("Failed to load config: unexpected end of file. Truncated or empty configuration?") l.Fatalln("Failed to load config: unexpected end of file. Truncated or empty configuration?")
@ -1058,7 +1063,7 @@ func setupGUI(mainService *suture.Supervisor, cfg *config.Wrapper, m *model.Mode
// Can potentially block if the utility we are invoking doesn't // Can potentially block if the utility we are invoking doesn't
// fork, and just execs, hence keep it in its own routine. // fork, and just execs, hence keep it in its own routine.
<-api.startedOnce <-api.startedOnce
go openURL(guiCfg.URL()) go func() { _ = openURL(guiCfg.URL()) }()
} }
} }

View File

@ -30,7 +30,7 @@ func (c *mockedConfig) LDAP() config.LDAPConfiguration {
func (c *mockedConfig) RawCopy() config.Configuration { func (c *mockedConfig) RawCopy() config.Configuration {
cfg := config.Configuration{} cfg := config.Configuration{}
util.SetDefaults(&cfg.Options) _ = util.SetDefaults(&cfg.Options)
return cfg return cfg
} }

View File

@ -127,13 +127,13 @@ func monitorMain(runtimeOptions RuntimeOptions) {
select { select {
case s := <-stopSign: case s := <-stopSign:
l.Infof("Signal %d received; exiting", s) l.Infof("Signal %d received; exiting", s)
cmd.Process.Signal(sigTerm) _ = cmd.Process.Signal(sigTerm)
<-exit <-exit
return return
case s := <-restartSign: case s := <-restartSign:
l.Infof("Signal %d received; restarting", s) l.Infof("Signal %d received; restarting", s)
cmd.Process.Signal(sigHup) _ = cmd.Process.Signal(sigHup)
err = <-exit err = <-exit
case err = <-exit: case err = <-exit:
@ -179,7 +179,7 @@ func copyStderr(stderr io.Reader, dst io.Writer) {
} }
if panicFd == nil { if panicFd == nil {
dst.Write([]byte(line)) _, _ = dst.Write([]byte(line))
if strings.Contains(line, "SIGILL") { if strings.Contains(line, "SIGILL") {
l.Warnln(` l.Warnln(`
@ -226,20 +226,20 @@ func copyStderr(stderr io.Reader, dst io.Writer) {
stdoutMut.Lock() stdoutMut.Lock()
for _, line := range stdoutFirstLines { for _, line := range stdoutFirstLines {
panicFd.WriteString(line) _, _ = panicFd.WriteString(line)
} }
panicFd.WriteString("...\n") _, _ = panicFd.WriteString("...\n")
for _, line := range stdoutLastLines { for _, line := range stdoutLastLines {
panicFd.WriteString(line) _, _ = panicFd.WriteString(line)
} }
stdoutMut.Unlock() stdoutMut.Unlock()
} }
panicFd.WriteString("Panic at " + time.Now().Format(time.RFC3339) + "\n") _, _ = panicFd.WriteString("Panic at " + time.Now().Format(time.RFC3339) + "\n")
} }
if panicFd != nil { if panicFd != nil {
panicFd.WriteString(line) _, _ = panicFd.WriteString(line)
} }
} }
} }
@ -263,7 +263,7 @@ func copyStdout(stdout io.Reader, dst io.Writer) {
} }
stdoutMut.Unlock() stdoutMut.Unlock()
dst.Write([]byte(line)) _, _ = dst.Write([]byte(line))
} }
} }

View File

@ -17,7 +17,7 @@ import (
func TestAutoClosedFile(t *testing.T) { func TestAutoClosedFile(t *testing.T) {
os.RemoveAll("_autoclose") os.RemoveAll("_autoclose")
defer os.RemoveAll("_autoclose") defer os.RemoveAll("_autoclose")
os.Mkdir("_autoclose", 0755) _ = os.Mkdir("_autoclose", 0755)
file := filepath.FromSlash("_autoclose/tmp") file := filepath.FromSlash("_autoclose/tmp")
data := []byte("hello, world\n") data := []byte("hello, world\n")

View File

@ -38,7 +38,10 @@ func savePerfStats(file string) {
t0 := time.Now() t0 := time.Now()
for t := range time.NewTicker(250 * time.Millisecond).C { for t := range time.NewTicker(250 * time.Millisecond).C {
syscall.Getrusage(syscall.RUSAGE_SELF, &rusage) if err := syscall.Getrusage(syscall.RUSAGE_SELF, &rusage); err != nil {
continue
}
curTime := time.Now().UnixNano() curTime := time.Now().UnixNano()
timeDiff := curTime - prevTime timeDiff := curTime - prevTime
curUsage := rusage.Utime.Nano() + rusage.Stime.Nano() curUsage := rusage.Utime.Nano() + rusage.Stime.Nano()

View File

@ -19,11 +19,11 @@ func optionTable(w io.Writer, rows [][]string) {
for _, row := range rows { for _, row := range rows {
for i, cell := range row { for i, cell := range row {
if i > 0 { if i > 0 {
tw.Write([]byte("\t")) _, _ = tw.Write([]byte("\t"))
} }
tw.Write([]byte(cell)) _, _ = tw.Write([]byte(cell))
} }
tw.Write([]byte("\n")) _, _ = tw.Write([]byte("\n"))
} }
tw.Flush() tw.Flush()
} }

View File

@ -348,7 +348,9 @@ func newUsageReportingService(cfg *config.Wrapper, model *model.Model, connectio
func (s *usageReportingService) sendUsageReport() error { func (s *usageReportingService) sendUsageReport() error {
d := reportData(s.cfg, s.model, s.connectionsService, s.cfg.Options().URAccepted, false) d := reportData(s.cfg, s.model, s.connectionsService, s.cfg.Options().URAccepted, false)
var b bytes.Buffer var b bytes.Buffer
json.NewEncoder(&b).Encode(d) if err := json.NewEncoder(&b).Encode(d); err != nil {
return err
}
client := &http.Client{ client := &http.Client{
Transport: &http.Transport{ Transport: &http.Transport{
@ -417,7 +419,7 @@ func (s *usageReportingService) Stop() {
s.stopMut.RUnlock() s.stopMut.RUnlock()
} }
func (usageReportingService) String() string { func (*usageReportingService) String() string {
return "usageReportingService" return "usageReportingService"
} }
@ -425,7 +427,7 @@ func (usageReportingService) String() string {
func cpuBench(iterations int, duration time.Duration, useWeakHash bool) float64 { func cpuBench(iterations int, duration time.Duration, useWeakHash bool) float64 {
dataSize := 16 * protocol.MinBlockSize dataSize := 16 * protocol.MinBlockSize
bs := make([]byte, dataSize) bs := make([]byte, dataSize)
rand.Reader.Read(bs) _, _ = rand.Reader.Read(bs)
var perf float64 var perf float64
for i := 0; i < iterations; i++ { for i := 0; i < iterations; i++ {

View File

@ -60,14 +60,13 @@ type copyBlocksState struct {
const retainBits = fs.ModeSetgid | fs.ModeSetuid | fs.ModeSticky const retainBits = fs.ModeSetgid | fs.ModeSetuid | fs.ModeSticky
var ( var (
activity = newDeviceActivity() activity = newDeviceActivity()
errNoDevice = errors.New("peers who had this file went away, or the file has changed while syncing. will retry later") errNoDevice = errors.New("peers who had this file went away, or the file has changed while syncing. will retry later")
errSymlinksUnsupported = errors.New("symlinks not supported") errDirHasToBeScanned = errors.New("directory contains unexpected files, scheduling scan")
errDirHasToBeScanned = errors.New("directory contains unexpected files, scheduling scan") errDirHasIgnored = errors.New("directory contains ignored files (see ignore documentation for (?d) prefix)")
errDirHasIgnored = errors.New("directory contains ignored files (see ignore documentation for (?d) prefix)") errDirNotEmpty = errors.New("directory is not empty; files within are probably ignored on connected devices only")
errDirNotEmpty = errors.New("directory is not empty; files within are probably ignored on connected devices only") errNotAvailable = errors.New("no connected device has the required version of this file")
errNotAvailable = errors.New("no connected device has the required version of this file") errModified = errors.New("file modified but not rescanned; will try again later")
errModified = errors.New("file modified but not rescanned; will try again later")
) )
const ( const (
@ -882,7 +881,8 @@ func (f *sendReceiveFolder) renameFile(cur, source, target protocol.FileInfo, ig
scanChan <- target.Name scanChan <- target.Name
err = errModified err = errModified
default: default:
if fi, err := scanner.CreateFileInfo(stat, target.Name, f.fs); err == nil { var fi protocol.FileInfo
if fi, err = scanner.CreateFileInfo(stat, target.Name, f.fs); err == nil {
if !fi.IsEquivalentOptional(curTarget, f.IgnorePerms, true, protocol.LocalAllFlags) { if !fi.IsEquivalentOptional(curTarget, f.IgnorePerms, true, protocol.LocalAllFlags) {
// Target changed // Target changed
scanChan <- target.Name scanChan <- target.Name
@ -1016,7 +1016,7 @@ func (f *sendReceiveFolder) handleFile(file protocol.FileInfo, copyChan chan<- c
// Otherwise, discard the file ourselves in order for the // Otherwise, discard the file ourselves in order for the
// sharedpuller not to panic when it fails to exclusively create a // sharedpuller not to panic when it fails to exclusively create a
// file which already exists // file which already exists
osutil.InWritableDir(f.fs.Remove, f.fs, tempName) _ = osutil.InWritableDir(f.fs.Remove, f.fs, tempName)
} }
} else { } else {
// Copy the blocks, as we don't want to shuffle them on the FileInfo // Copy the blocks, as we don't want to shuffle them on the FileInfo
@ -1142,7 +1142,7 @@ func (f *sendReceiveFolder) shortcutFile(file, curFile protocol.FileInfo, dbUpda
} }
} }
f.fs.Chtimes(file.Name, file.ModTime(), file.ModTime()) // never fails _ = f.fs.Chtimes(file.Name, file.ModTime(), file.ModTime()) // never fails
// This may have been a conflict. We should merge the version vectors so // This may have been a conflict. We should merge the version vectors so
// that our clock doesn't move backwards. // that our clock doesn't move backwards.
@ -1536,7 +1536,7 @@ func (f *sendReceiveFolder) performFinish(ignores *ignore.Matcher, file, curFile
} }
// Set the correct timestamp on the new file // Set the correct timestamp on the new file
f.fs.Chtimes(file.Name, file.ModTime(), file.ModTime()) // never fails _ = f.fs.Chtimes(file.Name, file.ModTime(), file.ModTime()) // never fails
// Record the updated file in the index // Record the updated file in the index
dbUpdateChan <- dbUpdateJob{file, dbUpdateHandleFile} dbUpdateChan <- dbUpdateJob{file, dbUpdateHandleFile}
@ -1706,7 +1706,7 @@ func (f *sendReceiveFolder) pullScannerRoutine(scanChan <-chan string) {
l.Debugln(f, "scheduling scan after pulling for", path) l.Debugln(f, "scheduling scan after pulling for", path)
scanList = append(scanList, path) scanList = append(scanList, path)
} }
f.Scan(scanList) _ = f.Scan(scanList)
} }
} }
@ -1858,7 +1858,7 @@ func (f *sendReceiveFolder) deleteDir(dir string, ignores *ignore.Matcher, scanC
} }
for _, del := range toBeDeleted { for _, del := range toBeDeleted {
f.fs.RemoveAll(del) _ = f.fs.RemoveAll(del)
} }
err := osutil.InWritableDir(f.fs.Remove, f.fs, dir) err := osutil.InWritableDir(f.fs.Remove, f.fs, dir)

View File

@ -258,9 +258,9 @@ func (m *Model) startFolderLocked(folder string) config.FolderType {
ffs := fs.MtimeFS() ffs := fs.MtimeFS()
// These are our metadata files, and they should always be hidden. // These are our metadata files, and they should always be hidden.
ffs.Hide(config.DefaultMarkerName) _ = ffs.Hide(config.DefaultMarkerName)
ffs.Hide(".stversions") _ = ffs.Hide(".stversions")
ffs.Hide(".stignore") _ = ffs.Hide(".stignore")
p := folderFactory(m, cfg, ver, ffs) p := folderFactory(m, cfg, ver, ffs)
@ -338,7 +338,7 @@ func (m *Model) RemoveFolder(cfg config.FolderConfiguration) {
m.fmut.Lock() m.fmut.Lock()
m.pmut.Lock() m.pmut.Lock()
// Delete syncthing specific files // Delete syncthing specific files
cfg.Filesystem().RemoveAll(config.DefaultMarkerName) _ = cfg.Filesystem().RemoveAll(config.DefaultMarkerName)
m.tearDownFolderLocked(cfg, fmt.Errorf("removing folder %v", cfg.Description())) m.tearDownFolderLocked(cfg, fmt.Errorf("removing folder %v", cfg.Description()))
// Remove it from the database // Remove it from the database
@ -362,7 +362,7 @@ func (m *Model) tearDownFolderLocked(cfg config.FolderConfiguration, err error)
m.pmut.Unlock() m.pmut.Unlock()
m.fmut.Unlock() m.fmut.Unlock()
for _, id := range tokens { for _, id := range tokens {
m.RemoveAndWait(id, 0) _ = m.RemoveAndWait(id, 0)
} }
m.fmut.Lock() m.fmut.Lock()
m.pmut.Lock() m.pmut.Lock()
@ -1189,7 +1189,7 @@ func (m *Model) handleIntroductions(introducerCfg config.DeviceConfiguration, cm
} }
if changed { if changed {
m.cfg.SetFolder(fcfg) _, _ = m.cfg.SetFolder(fcfg)
} }
} }
@ -1246,7 +1246,7 @@ func (m *Model) handleDeintroductions(introducerCfg config.DeviceConfiguration,
cfg := m.cfg.RawCopy() cfg := m.cfg.RawCopy()
cfg.Folders = folders cfg.Folders = folders
cfg.Devices = devices cfg.Devices = devices
m.cfg.Replace(cfg) _, _ = m.cfg.Replace(cfg)
} }
return changed return changed
@ -1325,7 +1325,7 @@ func (m *Model) introduceDevice(device protocol.Device, introducerCfg config.Dev
newDeviceCfg.SkipIntroductionRemovals = device.SkipIntroductionRemovals newDeviceCfg.SkipIntroductionRemovals = device.SkipIntroductionRemovals
} }
m.cfg.SetDevice(newDeviceCfg) _, _ = m.cfg.SetDevice(newDeviceCfg)
} }
// Closed is called when a connection has been closed // Closed is called when a connection has been closed
@ -1776,8 +1776,8 @@ func (m *Model) AddConnection(conn connections.Connection, hello protocol.HelloR
if (device.Name == "" || m.cfg.Options().OverwriteRemoteDevNames) && hello.DeviceName != "" { if (device.Name == "" || m.cfg.Options().OverwriteRemoteDevNames) && hello.DeviceName != "" {
device.Name = hello.DeviceName device.Name = hello.DeviceName
m.cfg.SetDevice(device) _, _ = m.cfg.SetDevice(device)
m.cfg.Save() _ = m.cfg.Save()
} }
m.deviceWasSeen(deviceID) m.deviceWasSeen(deviceID)
@ -1864,7 +1864,7 @@ func sendIndexes(conn protocol.Connection, folder string, fs *db.FileSet, ignore
// local index may update for other folders than the one we are // local index may update for other folders than the one we are
// sending for. // sending for.
if fs.Sequence(protocol.LocalDeviceID) <= prevSequence { if fs.Sequence(protocol.LocalDeviceID) <= prevSequence {
sub.Poll(time.Minute) _, _ = sub.Poll(time.Minute)
continue continue
} }
@ -2484,7 +2484,7 @@ func (m *Model) RestoreFolderVersions(folder string, versions map[string]time.Ti
} }
} }
filesystem.MkdirAll(filepath.Dir(target), 0755) _ = filesystem.MkdirAll(filepath.Dir(target), 0755)
if err == nil { if err == nil {
err = osutil.Copy(filesystem, source, target) err = osutil.Copy(filesystem, source, target)
} }
@ -2734,17 +2734,6 @@ func getChunk(data []string, skip, get int) ([]string, int, int) {
return data[skip : skip+get], 0, 0 return data[skip : skip+get], 0, 0
} }
func stringSliceWithout(ss []string, s string) []string {
for i := range ss {
if ss[i] == s {
copy(ss[i:], ss[i+1:])
ss = ss[:len(ss)-1]
return ss
}
}
return ss
}
func readOffsetIntoBuf(fs fs.Filesystem, file string, offset int64, buf []byte) error { func readOffsetIntoBuf(fs fs.Filesystem, file string, offset int64, buf []byte) error {
fd, err := fs.Open(file) fd, err := fs.Open(file)
if err != nil { if err != nil {

View File

@ -15,7 +15,7 @@ type Protocol string
const ( const (
TCP Protocol = "TCP" TCP Protocol = "TCP"
UDP = "UDP" UDP Protocol = "UDP"
) )
type Device interface { type Device interface {

View File

@ -92,7 +92,7 @@ func (s *Service) process() int {
toRenew = append(toRenew, mapping) toRenew = append(toRenew, mapping)
} else { } else {
toUpdate = append(toUpdate, mapping) toUpdate = append(toUpdate, mapping)
mappingRenewIn := mapping.expires.Sub(time.Now()) mappingRenewIn := time.Until(mapping.expires)
if mappingRenewIn < renewIn { if mappingRenewIn < renewIn {
renewIn = mappingRenewIn renewIn = mappingRenewIn
} }
@ -328,6 +328,6 @@ findIP:
func hash(input string) int64 { func hash(input string) int64 {
h := fnv.New64a() h := fnv.New64a()
h.Write([]byte(input)) _, _ = h.Write([]byte(input))
return int64(h.Sum64()) return int64(h.Sum64())
} }

View File

@ -77,12 +77,7 @@ func readHello(c io.Reader) (HelloResult, error) {
if err := hello.Unmarshal(buf); err != nil { if err := hello.Unmarshal(buf); err != nil {
return HelloResult{}, err return HelloResult{}, err
} }
res := HelloResult{ return HelloResult(hello), nil
DeviceName: hello.DeviceName,
ClientName: hello.ClientName,
ClientVersion: hello.ClientVersion,
}
return res, nil
case 0x00010001, 0x00010000, Version13HelloMagic: case 0x00010001, 0x00010000, Version13HelloMagic:
// This is the first word of an older cluster config message or an // This is the first word of an older cluster config message or an

View File

@ -83,10 +83,10 @@ type Relation int
const ( const (
MajorOlder Relation = -2 // Older by a major version (x in x.y.z or 0.x.y). MajorOlder Relation = -2 // Older by a major version (x in x.y.z or 0.x.y).
Older = -1 // Older by a minor version (y or z in x.y.z, or y in 0.x.y) Older Relation = -1 // Older by a minor version (y or z in x.y.z, or y in 0.x.y)
Equal = 0 // Versions are semantically equal Equal Relation = 0 // Versions are semantically equal
Newer = 1 // Newer by a minor version (y or z in x.y.z, or y in 0.x.y) Newer Relation = 1 // Newer by a minor version (y or z in x.y.z, or y in 0.x.y)
MajorNewer = 2 // Newer by a major version (x in x.y.z or 0.x.y). MajorNewer Relation = 2 // Newer by a major version (x in x.y.z or 0.x.y).
) )
// CompareVersions returns a relation describing how a compares to b. // CompareVersions returns a relation describing how a compares to b.