all: Unused args, retvals, assignments (#7926)

This commit is contained in:
greatroar 2021-09-08 00:11:16 +02:00 committed by GitHub
parent 13196ddd92
commit 7fa141ea39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 52 additions and 50 deletions

View File

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.
// Commmand stfindignored lists ignored files under a given folder root.
// Command stfindignored lists ignored files under a given folder root.
package main
import (

View File

@ -54,7 +54,7 @@ func indexDumpOutput(url string) cli.ActionFunc {
if err != nil {
return err
}
return prettyPrintResponse(c, response)
return prettyPrintResponse(response)
}
}
@ -130,7 +130,7 @@ func prettyPrintJSON(data interface{}) error {
return enc.Encode(data)
}
func prettyPrintResponse(c *cli.Context, response *http.Response) error {
func prettyPrintResponse(response *http.Response) error {
bytes, err := responseToBArray(response)
if err != nil {
return err

View File

@ -412,7 +412,7 @@ func (options serveOptions) Run() error {
}
func openGUI(myID protocol.DeviceID) error {
cfg, err := loadOrDefaultConfig(myID, events.NoopLogger, true)
cfg, err := loadOrDefaultConfig(myID, events.NoopLogger)
if err != nil {
return err
}
@ -497,7 +497,7 @@ func (e *errNoUpgrade) Error() string {
}
func checkUpgrade() (upgrade.Release, error) {
cfg, err := loadOrDefaultConfig(protocol.EmptyDeviceID, events.NoopLogger, true)
cfg, err := loadOrDefaultConfig(protocol.EmptyDeviceID, events.NoopLogger)
if err != nil {
return upgrade.Release{}, err
}
@ -516,7 +516,11 @@ func checkUpgrade() (upgrade.Release, error) {
}
func upgradeViaRest() error {
cfg, _ := loadOrDefaultConfig(protocol.EmptyDeviceID, events.NoopLogger, true)
cfg, err := loadOrDefaultConfig(protocol.EmptyDeviceID, events.NoopLogger)
if err != nil {
return err
}
u, err := url.Parse(cfg.GUI().URL())
if err != nil {
return err
@ -752,12 +756,12 @@ func setupSignalHandling(app *syncthing.App) {
}()
}
func loadOrDefaultConfig(myID protocol.DeviceID, evLogger events.Logger, noDefaultFolder bool) (config.Wrapper, error) {
func loadOrDefaultConfig(myID protocol.DeviceID, evLogger events.Logger) (config.Wrapper, error) {
cfgFile := locations.Get(locations.ConfigFile)
cfg, _, err := config.Load(cfgFile, myID, evLogger)
if err != nil {
cfg, err = syncthing.DefaultConfig(cfgFile, myID, evLogger, noDefaultFolder)
cfg, err = syncthing.DefaultConfig(cfgFile, myID, evLogger, true)
}
return cfg, err

View File

@ -564,7 +564,7 @@ func childEnv() []string {
// panicUploadMaxWait uploading panics...
func maybeReportPanics() {
// Try to get a config to see if/where panics should be reported.
cfg, err := loadOrDefaultConfig(protocol.EmptyDeviceID, events.NoopLogger, true)
cfg, err := loadOrDefaultConfig(protocol.EmptyDeviceID, events.NoopLogger)
if err != nil {
l.Warnln("Couldn't load config; not reporting crash")
return

View File

@ -66,7 +66,7 @@ func newStaticsServer(theme, assetDir string) *staticsServer {
func (s *staticsServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/themes.json":
s.serveThemes(w, r)
s.serveThemes(w)
default:
s.serveAsset(w, r)
}
@ -153,7 +153,7 @@ func (s *staticsServer) serveFromAssets(file, theme string, modificationTime tim
return true
}
func (s *staticsServer) serveThemes(w http.ResponseWriter, r *http.Request) {
func (s *staticsServer) serveThemes(w http.ResponseWriter) {
sendJSON(w, map[string][]string{
"themes": s.availableThemes,
})

View File

@ -103,7 +103,7 @@ func writeBroadcasts(ctx context.Context, inbox <-chan []byte, port int) error {
}
if success == 0 {
l.Debugln("couldn't send any braodcasts")
l.Debugln("couldn't send any broadcasts")
return err
}
}

View File

@ -180,7 +180,7 @@ func (db *Lowlevel) updateRemoteFiles(folder, device []byte, fs []protocol.FileI
if err != nil {
return err
}
keyBuf, _, err = t.updateGlobal(gk, keyBuf, folder, device, f, meta)
keyBuf, err = t.updateGlobal(gk, keyBuf, folder, device, f, meta)
if err != nil {
return err
}
@ -272,7 +272,7 @@ func (db *Lowlevel) updateLocalFiles(folder []byte, fs []protocol.FileInfo, meta
if err != nil {
return err
}
keyBuf, _, err = t.updateGlobal(gk, keyBuf, folder, protocol.LocalDeviceID[:], f, meta)
keyBuf, err = t.updateGlobal(gk, keyBuf, folder, protocol.LocalDeviceID[:], f, meta)
if err != nil {
return err
}

View File

@ -244,8 +244,7 @@ func (db *schemaUpdater) updateSchema0to1(_ int) error {
if err != nil && !backend.IsNotFound(err) {
return err
}
i := 0
i = sort.Search(len(fl.Versions), func(j int) bool {
i := sort.Search(len(fl.Versions), func(j int) bool {
return fl.Versions[j].Invalid
})
for ; i < len(fl.Versions); i++ {
@ -529,7 +528,7 @@ func (db *schemaUpdater) updateSchemaTo9(prev int) error {
}
defer t.close()
if err := db.rewriteFiles(t); err != nil {
if err := rewriteFiles(t); err != nil {
return err
}
@ -538,7 +537,7 @@ func (db *schemaUpdater) updateSchemaTo9(prev int) error {
return t.Commit()
}
func (db *schemaUpdater) rewriteFiles(t readWriteTransaction) error {
func rewriteFiles(t readWriteTransaction) error {
it, err := t.NewPrefixIterator([]byte{KeyTypeDevice})
if err != nil {
return err
@ -696,12 +695,12 @@ func (db *schemaUpdater) updateSchemaTo13(prev int) error {
defer t.close()
if prev < 12 {
if err := db.rewriteFiles(t); err != nil {
if err := rewriteFiles(t); err != nil {
return err
}
}
if err := db.rewriteGlobals(t); err != nil {
if err := rewriteGlobals(t); err != nil {
return err
}
@ -759,7 +758,7 @@ func (db *schemaUpdater) updateSchemaTo14(_ int) error {
if err != nil {
return err
}
key, _, err = t.updateGlobal(gk, key, folder, protocol.LocalDeviceID[:], fi, meta)
key, err = t.updateGlobal(gk, key, folder, protocol.LocalDeviceID[:], fi, meta)
if err != nil {
return err
}
@ -836,7 +835,7 @@ func (db *schemaUpdater) dropIndexIDsMigration(_ int) error {
return db.dropIndexIDs()
}
func (db *schemaUpdater) rewriteGlobals(t readWriteTransaction) error {
func rewriteGlobals(t readWriteTransaction) error {
it, err := t.NewPrefixIterator([]byte{KeyTypeGlobal})
if err != nil {
return err
@ -909,11 +908,9 @@ outer:
switch nfv.Version.Compare(fv.Version) {
case protocol.Equal:
newVl.RawVersions[newPos].InvalidDevices = append(newVl.RawVersions[newPos].InvalidDevices, fv.Device)
lastVersion = fv.Version
continue outer
case protocol.Lesser:
newVl.insertAt(newPos, newFileVersion(fv.Device, fv.Version, true, fv.Deleted))
lastVersion = fv.Version
continue outer
case protocol.ConcurrentLesser, protocol.ConcurrentGreater:
// The version is invalid, i.e. it looses anyway,
@ -923,7 +920,6 @@ outer:
}
// Couldn't insert into any existing versions
newVl.RawVersions = append(newVl.RawVersions, newFileVersion(fv.Device, fv.Version, true, fv.Deleted))
lastVersion = fv.Version
newPos++
}

View File

@ -207,17 +207,17 @@ func (t readOnlyTransaction) getGlobal(keyBuf, folder, file []byte, truncate boo
return nil, nil, false, err
}
var fi protocol.FileIntf
keyBuf, fi, _, err = t.getGlobalFromVersionList(keyBuf, folder, file, truncate, vl)
keyBuf, fi, err = t.getGlobalFromVersionList(keyBuf, folder, file, truncate, vl)
return keyBuf, fi, true, err
}
func (t readOnlyTransaction) getGlobalFromVersionList(keyBuf, folder, file []byte, truncate bool, vl VersionList) ([]byte, protocol.FileIntf, FileVersion, error) {
func (t readOnlyTransaction) getGlobalFromVersionList(keyBuf, folder, file []byte, truncate bool, vl VersionList) ([]byte, protocol.FileIntf, error) {
fv, ok := vl.GetGlobal()
if !ok {
return keyBuf, nil, FileVersion{}, errEmptyGlobal
return keyBuf, nil, errEmptyGlobal
}
keyBuf, fi, err := t.getGlobalFromFileVersion(keyBuf, folder, file, truncate, fv)
return keyBuf, fi, fv, err
return keyBuf, fi, err
}
func (t readOnlyTransaction) getGlobalFromFileVersion(keyBuf, folder, file []byte, truncate bool, fv FileVersion) ([]byte, protocol.FileIntf, error) {
@ -363,7 +363,7 @@ func (t *readOnlyTransaction) withGlobal(folder, prefix []byte, truncate bool, f
}
var f protocol.FileIntf
dk, f, _, err = t.getGlobalFromVersionList(dk, folder, name, truncate, vl)
dk, f, err = t.getGlobalFromVersionList(dk, folder, name, truncate, vl)
if err != nil {
return err
}
@ -626,29 +626,29 @@ func (t readWriteTransaction) putFile(fkey []byte, fi protocol.FileInfo) error {
// updateGlobal adds this device+version to the version list for the given
// file. If the device is already present in the list, the version is updated.
// If the file does not have an entry in the global list, it is created.
func (t readWriteTransaction) updateGlobal(gk, keyBuf, folder, device []byte, file protocol.FileInfo, meta *metadataTracker) ([]byte, bool, error) {
func (t readWriteTransaction) updateGlobal(gk, keyBuf, folder, device []byte, file protocol.FileInfo, meta *metadataTracker) ([]byte, error) {
deviceID, err := protocol.DeviceIDFromBytes(device)
if err != nil {
return nil, false, err
return nil, err
}
l.Debugf("update global; folder=%q device=%v file=%q version=%v invalid=%v", folder, deviceID, file.Name, file.Version, file.IsInvalid())
fl, err := t.getGlobalVersionsByKey(gk)
if err != nil && !backend.IsNotFound(err) {
return nil, false, err
return nil, err
}
globalFV, oldGlobalFV, removedFV, haveOldGlobal, haveRemoved, globalChanged, err := fl.update(folder, device, file, t.readOnlyTransaction)
if err != nil {
return nil, false, err
return nil, err
}
name := []byte(file.Name)
l.Debugf(`new global for "%v" after update: %v`, file.Name, fl)
if err := t.Put(gk, mustMarshal(&fl)); err != nil {
return nil, false, err
return nil, err
}
// Only load those from db if actually needed
@ -664,26 +664,26 @@ func (t readWriteTransaction) updateGlobal(gk, keyBuf, folder, device []byte, fi
needNow := Need(globalFV, true, file.Version)
if needBefore {
if keyBuf, oldGlobal, err = t.getGlobalFromFileVersion(keyBuf, folder, name, true, oldGlobalFV); err != nil {
return nil, false, err
return nil, err
}
gotOldGlobal = true
meta.removeNeeded(deviceID, oldGlobal)
if !needNow && bytes.Equal(device, protocol.LocalDeviceID[:]) {
if keyBuf, err = t.updateLocalNeed(keyBuf, folder, name, false); err != nil {
return nil, false, err
return nil, err
}
}
}
if needNow {
keyBuf, global, err = t.getGlobalFromFileVersion(keyBuf, folder, name, true, globalFV)
if err != nil {
return nil, false, err
return nil, err
}
gotGlobal = true
meta.addNeeded(deviceID, global)
if !needBefore && bytes.Equal(device, protocol.LocalDeviceID[:]) {
if keyBuf, err = t.updateLocalNeed(keyBuf, folder, name, true); err != nil {
return nil, false, err
return nil, err
}
}
}
@ -693,16 +693,15 @@ func (t readWriteTransaction) updateGlobal(gk, keyBuf, folder, device []byte, fi
if !globalChanged {
// Neither the global state nor the needs of any devices, except
// the one updated, changed.
return keyBuf, true, nil
return keyBuf, nil
}
// Remove the old global from the global size counter
if haveOldGlobal {
if !gotOldGlobal {
if keyBuf, oldGlobal, err = t.getGlobalFromFileVersion(keyBuf, folder, name, true, oldGlobalFV); err != nil {
return nil, false, err
return nil, err
}
gotOldGlobal = true
}
// Remove the old global from the global size counter
meta.removeFile(protocol.GlobalDeviceID, oldGlobal)
@ -715,6 +714,9 @@ func (t readWriteTransaction) updateGlobal(gk, keyBuf, folder, device []byte, fi
global = file
} else {
keyBuf, global, err = t.getGlobalFromFileVersion(keyBuf, folder, name, true, globalFV)
if err != nil {
return nil, err
}
}
gotGlobal = true
}
@ -729,7 +731,7 @@ func (t readWriteTransaction) updateGlobal(gk, keyBuf, folder, device []byte, fi
meta.removeNeeded(protocol.LocalDeviceID, oldGlobal)
if !needNow {
if keyBuf, err = t.updateLocalNeed(keyBuf, folder, name, false); err != nil {
return nil, false, err
return nil, err
}
}
}
@ -737,7 +739,7 @@ func (t readWriteTransaction) updateGlobal(gk, keyBuf, folder, device []byte, fi
meta.addNeeded(protocol.LocalDeviceID, global)
if !needBefore {
if keyBuf, err = t.updateLocalNeed(keyBuf, folder, name, true); err != nil {
return nil, false, err
return nil, err
}
}
}
@ -757,7 +759,7 @@ func (t readWriteTransaction) updateGlobal(gk, keyBuf, folder, device []byte, fi
}
}
return keyBuf, true, nil
return keyBuf, nil
}
func (t readWriteTransaction) updateLocalNeed(keyBuf, folder, name []byte, add bool) ([]byte, error) {
@ -838,7 +840,7 @@ func (t readWriteTransaction) removeFromGlobal(gk, keyBuf, folder, device, file
globalFV, haveGlobal := fl.GetGlobal()
// Add potential needs of the removed device
if haveGlobal && !globalFV.IsInvalid() && Need(globalFV, false, protocol.Vector{}) && !Need(oldGlobalFV, haveRemoved, removedFV.Version) {
keyBuf, global, _, err = t.getGlobalFromVersionList(keyBuf, folder, file, true, fl)
keyBuf, global, err = t.getGlobalFromVersionList(keyBuf, folder, file, true, fl)
if err != nil {
return nil, err
}
@ -900,7 +902,7 @@ func (t readWriteTransaction) removeFromGlobal(gk, keyBuf, folder, device, file
// Add to global
if !gotGlobal {
keyBuf, global, _, err = t.getGlobalFromVersionList(keyBuf, folder, file, true, fl)
keyBuf, global, err = t.getGlobalFromVersionList(keyBuf, folder, file, true, fl)
if err != nil {
return nil, err
}

View File

@ -189,7 +189,7 @@ func (m *Matcher) Load(file string) error {
return nil
}
fd, info, err := loadIgnoreFile(m.fs, file, m.changeDetector)
fd, info, err := loadIgnoreFile(m.fs, file)
if err != nil {
m.parseLocked(&bytes.Buffer{}, file)
return err
@ -381,7 +381,7 @@ func hashPatterns(patterns []Pattern) string {
return fmt.Sprintf("%x", h.Sum(nil))
}
func loadIgnoreFile(fs fs.Filesystem, file string, cd ChangeDetector) (fs.File, fs.FileInfo, error) {
func loadIgnoreFile(fs fs.Filesystem, file string) (fs.File, fs.FileInfo, error) {
fd, err := fs.Open(file)
if err != nil {
return fd, nil, err
@ -411,7 +411,7 @@ func loadParseIncludeFile(filesystem fs.Filesystem, file string, cd ChangeDetect
return nil, parseError(fmt.Errorf("multiple include of ignore file %q", file))
}
fd, info, err := loadIgnoreFile(filesystem, file, cd)
fd, info, err := loadIgnoreFile(filesystem, file)
if err != nil {
return nil, err
}