From 0a58747eb2702ebf5969e0a691de018dee1a063c Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Tue, 20 May 2025 15:04:33 +0200 Subject: [PATCH] chore: further minor lint fixes --- .golangci.yml | 2 ++ lib/model/blockpullreorderer.go | 2 +- lib/model/devicedownloadstate.go | 4 ++-- lib/model/folder_sendrecv.go | 8 ++++---- lib/model/indexhandler.go | 14 ++++++++++---- lib/model/model.go | 6 +++--- lib/model/sentdownloadstate.go | 2 +- lib/model/service_map.go | 4 ++-- 8 files changed, 25 insertions(+), 17 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index b5b8239ff..6d83857a3 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -4,6 +4,7 @@ linters: disable: - cyclop - depguard + - err113 - exhaustive - exhaustruct - forbidigo @@ -53,6 +54,7 @@ linters: - third_party$ - builtin$ - examples$ + - _test\.go$ formatters: enable: - gofumpt diff --git a/lib/model/blockpullreorderer.go b/lib/model/blockpullreorderer.go index c2292c279..a98a4ce7a 100644 --- a/lib/model/blockpullreorderer.go +++ b/lib/model/blockpullreorderer.go @@ -92,7 +92,7 @@ func (p *standardBlockPullReorderer) Reorder(blocks []protocol.BlockInfo) []prot // The rest of the chunks we fetch in a random order in whole chunks. // Generate chunk index slice and shuffle it indexes := make([]int, 0, len(chunks)-1) - for i := 0; i < len(chunks); i++ { + for i := range len(chunks) { if i != p.myIndex { indexes = append(indexes, i) } diff --git a/lib/model/devicedownloadstate.go b/lib/model/devicedownloadstate.go index 13059499a..324cd8513 100644 --- a/lib/model/devicedownloadstate.go +++ b/lib/model/devicedownloadstate.go @@ -60,12 +60,12 @@ func (p *deviceFolderDownloadState) Update(updates []protocol.FileDownloadProgre local = deviceFolderFileDownloadState{ blockIndexes: update.BlockIndexes, version: update.Version, - blockSize: int(update.BlockSize), + blockSize: update.BlockSize, } } else if !local.version.Equal(update.Version) { local.blockIndexes = append(local.blockIndexes[:0], update.BlockIndexes...) local.version = update.Version - local.blockSize = int(update.BlockSize) + local.blockSize = update.BlockSize } else { local.blockIndexes = append(local.blockIndexes, update.BlockIndexes...) } diff --git a/lib/model/folder_sendrecv.go b/lib/model/folder_sendrecv.go index 8ab78400f..70cd37838 100644 --- a/lib/model/folder_sendrecv.go +++ b/lib/model/folder_sendrecv.go @@ -179,7 +179,7 @@ func (f *sendReceiveFolder) pull() (bool, error) { f.errorsMut.Unlock() var err error - for tries := 0; tries < maxPullerIterations; tries++ { + for tries := range maxPullerIterations { select { case <-f.ctx.Done(): return false, f.ctx.Err() @@ -259,7 +259,7 @@ func (f *sendReceiveFolder) pullerIteration(scanChan chan<- string) (int, error) updateWg.Done() }() - for i := 0; i < f.Copiers; i++ { + for range f.Copiers { copyWg.Add(1) go func() { // copierRoutine finishes when copyChan is closed @@ -1358,7 +1358,7 @@ func (f *sendReceiveFolder) copierRoutine(in <-chan copyBlocksState, pullChan ch // Returns true when the block was successfully copied. func (f *sendReceiveFolder) copyBlock(block protocol.BlockInfo, state copyBlocksState, otherFolderFilesystems map[string]fs.Filesystem) bool { - buf := protocol.BufferPool.Get(int(block.Size)) + buf := protocol.BufferPool.Get(block.Size) defer protocol.BufferPool.Put(buf) // Hope that it's usually in the same folder, so start with that @@ -1561,7 +1561,7 @@ loop: activity.using(selected) var buf []byte blockNo := int(state.block.Offset / int64(state.file.BlockSize())) - buf, lastError = f.model.RequestGlobal(f.ctx, selected.ID, f.folderID, state.file.Name, blockNo, state.block.Offset, int(state.block.Size), state.block.Hash, selected.FromTemporary) + buf, lastError = f.model.RequestGlobal(f.ctx, selected.ID, f.folderID, state.file.Name, blockNo, state.block.Offset, state.block.Size, state.block.Hash, selected.FromTemporary) activity.done(selected) if lastError != nil { l.Debugln("request:", f.folderID, state.file.Name, state.block.Offset, state.block.Size, selected.ID.Short(), "returned error:", lastError) diff --git a/lib/model/indexhandler.go b/lib/model/indexhandler.go index 4155bf9a2..d8c45da24 100644 --- a/lib/model/indexhandler.go +++ b/lib/model/indexhandler.go @@ -106,7 +106,9 @@ func newIndexHandler(conn protocol.Connection, downloads *deviceDownloadState, f // information we have from them before accepting their // index, which will presumably be a full index. l.Debugf("Device %v folder %s does not announce an index ID", conn.DeviceID().Short(), folder.Description()) - sdb.DropAllFiles(folder.ID, conn.DeviceID()) + if err := sdb.DropAllFiles(folder.ID, conn.DeviceID()); err != nil { + return nil, err + } } else if startInfo.remote.IndexID != theirIndexID { // The index ID we have on file is not what they're // announcing. They must have reset their database and @@ -114,8 +116,12 @@ func newIndexHandler(conn protocol.Connection, downloads *deviceDownloadState, f // information we have and remember this new index ID // instead. l.Infof("Device %v folder %s has a new index ID (%v)", conn.DeviceID().Short(), folder.Description(), startInfo.remote.IndexID) - sdb.DropAllFiles(folder.ID, conn.DeviceID()) - sdb.SetIndexID(folder.ID, conn.DeviceID(), startInfo.remote.IndexID) + if err := sdb.DropAllFiles(folder.ID, conn.DeviceID()); err != nil { + return nil, err + } + if err := sdb.SetIndexID(folder.ID, conn.DeviceID(), startInfo.remote.IndexID); err != nil { + return nil, err + } } return &indexHandler{ @@ -133,7 +139,7 @@ func newIndexHandler(conn protocol.Connection, downloads *deviceDownloadState, f }, nil } -// waitWhilePaused waits for the handler to resume +// waitWhilePaused waits for the handler to resume. func (s *indexHandler) waitWhilePaused(ctx context.Context) error { s.cond.L.Lock() defer s.cond.L.Unlock() diff --git a/lib/model/model.go b/lib/model/model.go index 9d46d925d..e9fa0b1d3 100644 --- a/lib/model/model.go +++ b/lib/model/model.go @@ -372,7 +372,7 @@ func (m *model) addAndStartFolderLockedWithIgnores(cfg config.FolderConfiguratio for _, available := range devs { if _, ok := expected[available]; !ok { l.Debugln("dropping", folder, "state for", available) - m.sdb.DropAllFiles(folder, available) + _ = m.sdb.DropAllFiles(folder, available) } } @@ -493,7 +493,7 @@ func (m *model) removeFolder(cfg config.FolderConfiguration) { m.mut.Unlock() // Remove it from the database - m.sdb.DropFolder(cfg.ID) + _ = m.sdb.DropFolder(cfg.ID) } // Need to hold lock on m.mut when calling this. @@ -1559,7 +1559,7 @@ func (m *model) ccCheckEncryption(fcfg config.FolderConfiguration, folderDevice if isEncryptedRemote { passwordToken := protocol.PasswordToken(m.keyGen, fcfg.ID, folderDevice.EncryptionPassword) - match := false + var match bool if hasTokenLocal { match = bytes.Equal(passwordToken, ccDeviceInfos.local.EncryptionPasswordToken) } else { diff --git a/lib/model/sentdownloadstate.go b/lib/model/sentdownloadstate.go index 2c205a7ad..e5723dd4d 100644 --- a/lib/model/sentdownloadstate.go +++ b/lib/model/sentdownloadstate.go @@ -97,7 +97,7 @@ func (s *sentFolderDownloadState) update(pullers []*sharedPullerState) []protoco localFile.updated = pullerBlockIndexesUpdated localFile.version = pullerVersion localFile.created = pullerCreated - localFile.blockSize = int(pullerBlockSize) + localFile.blockSize = pullerBlockSize continue } diff --git a/lib/model/service_map.go b/lib/model/service_map.go index 7eaf94506..cc681e9d1 100644 --- a/lib/model/service_map.go +++ b/lib/model/service_map.go @@ -8,6 +8,7 @@ package model import ( "context" + "errors" "fmt" "time" @@ -16,7 +17,7 @@ import ( "github.com/thejerf/suture/v4" ) -var errSvcNotFound = fmt.Errorf("service not found") +var errSvcNotFound = errors.New("service not found") // A serviceMap is a utility map of arbitrary keys to a suture.Service of // some kind, where adding and removing services ensures they are properly @@ -65,7 +66,6 @@ func (s *serviceMap[K, S]) Stop(k K) { if tok, ok := s.tokens[k]; ok { s.supervisor.Remove(tok) } - return } // StopAndWaitChan removes the service at the given key from the supervisor,