chore: further minor lint fixes
This commit is contained in:
@@ -4,6 +4,7 @@ linters:
|
|||||||
disable:
|
disable:
|
||||||
- cyclop
|
- cyclop
|
||||||
- depguard
|
- depguard
|
||||||
|
- err113
|
||||||
- exhaustive
|
- exhaustive
|
||||||
- exhaustruct
|
- exhaustruct
|
||||||
- forbidigo
|
- forbidigo
|
||||||
@@ -53,6 +54,7 @@ linters:
|
|||||||
- third_party$
|
- third_party$
|
||||||
- builtin$
|
- builtin$
|
||||||
- examples$
|
- examples$
|
||||||
|
- _test\.go$
|
||||||
formatters:
|
formatters:
|
||||||
enable:
|
enable:
|
||||||
- gofumpt
|
- gofumpt
|
||||||
|
|||||||
@@ -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.
|
// The rest of the chunks we fetch in a random order in whole chunks.
|
||||||
// Generate chunk index slice and shuffle it
|
// Generate chunk index slice and shuffle it
|
||||||
indexes := make([]int, 0, len(chunks)-1)
|
indexes := make([]int, 0, len(chunks)-1)
|
||||||
for i := 0; i < len(chunks); i++ {
|
for i := range len(chunks) {
|
||||||
if i != p.myIndex {
|
if i != p.myIndex {
|
||||||
indexes = append(indexes, i)
|
indexes = append(indexes, i)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,12 +60,12 @@ func (p *deviceFolderDownloadState) Update(updates []protocol.FileDownloadProgre
|
|||||||
local = deviceFolderFileDownloadState{
|
local = deviceFolderFileDownloadState{
|
||||||
blockIndexes: update.BlockIndexes,
|
blockIndexes: update.BlockIndexes,
|
||||||
version: update.Version,
|
version: update.Version,
|
||||||
blockSize: int(update.BlockSize),
|
blockSize: update.BlockSize,
|
||||||
}
|
}
|
||||||
} else if !local.version.Equal(update.Version) {
|
} else if !local.version.Equal(update.Version) {
|
||||||
local.blockIndexes = append(local.blockIndexes[:0], update.BlockIndexes...)
|
local.blockIndexes = append(local.blockIndexes[:0], update.BlockIndexes...)
|
||||||
local.version = update.Version
|
local.version = update.Version
|
||||||
local.blockSize = int(update.BlockSize)
|
local.blockSize = update.BlockSize
|
||||||
} else {
|
} else {
|
||||||
local.blockIndexes = append(local.blockIndexes, update.BlockIndexes...)
|
local.blockIndexes = append(local.blockIndexes, update.BlockIndexes...)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ func (f *sendReceiveFolder) pull() (bool, error) {
|
|||||||
f.errorsMut.Unlock()
|
f.errorsMut.Unlock()
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
for tries := 0; tries < maxPullerIterations; tries++ {
|
for tries := range maxPullerIterations {
|
||||||
select {
|
select {
|
||||||
case <-f.ctx.Done():
|
case <-f.ctx.Done():
|
||||||
return false, f.ctx.Err()
|
return false, f.ctx.Err()
|
||||||
@@ -259,7 +259,7 @@ func (f *sendReceiveFolder) pullerIteration(scanChan chan<- string) (int, error)
|
|||||||
updateWg.Done()
|
updateWg.Done()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
for i := 0; i < f.Copiers; i++ {
|
for range f.Copiers {
|
||||||
copyWg.Add(1)
|
copyWg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
// copierRoutine finishes when copyChan is closed
|
// 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.
|
// Returns true when the block was successfully copied.
|
||||||
func (f *sendReceiveFolder) copyBlock(block protocol.BlockInfo, state copyBlocksState, otherFolderFilesystems map[string]fs.Filesystem) bool {
|
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)
|
defer protocol.BufferPool.Put(buf)
|
||||||
|
|
||||||
// Hope that it's usually in the same folder, so start with that
|
// Hope that it's usually in the same folder, so start with that
|
||||||
@@ -1561,7 +1561,7 @@ loop:
|
|||||||
activity.using(selected)
|
activity.using(selected)
|
||||||
var buf []byte
|
var buf []byte
|
||||||
blockNo := int(state.block.Offset / int64(state.file.BlockSize()))
|
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)
|
activity.done(selected)
|
||||||
if lastError != nil {
|
if lastError != nil {
|
||||||
l.Debugln("request:", f.folderID, state.file.Name, state.block.Offset, state.block.Size, selected.ID.Short(), "returned error:", lastError)
|
l.Debugln("request:", f.folderID, state.file.Name, state.block.Offset, state.block.Size, selected.ID.Short(), "returned error:", lastError)
|
||||||
|
|||||||
@@ -106,7 +106,9 @@ func newIndexHandler(conn protocol.Connection, downloads *deviceDownloadState, f
|
|||||||
// information we have from them before accepting their
|
// information we have from them before accepting their
|
||||||
// index, which will presumably be a full index.
|
// 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())
|
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 {
|
} else if startInfo.remote.IndexID != theirIndexID {
|
||||||
// The index ID we have on file is not what they're
|
// The index ID we have on file is not what they're
|
||||||
// announcing. They must have reset their database and
|
// 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
|
// information we have and remember this new index ID
|
||||||
// instead.
|
// instead.
|
||||||
l.Infof("Device %v folder %s has a new index ID (%v)", conn.DeviceID().Short(), folder.Description(), startInfo.remote.IndexID)
|
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())
|
if err := sdb.DropAllFiles(folder.ID, conn.DeviceID()); err != nil {
|
||||||
sdb.SetIndexID(folder.ID, conn.DeviceID(), startInfo.remote.IndexID)
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := sdb.SetIndexID(folder.ID, conn.DeviceID(), startInfo.remote.IndexID); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &indexHandler{
|
return &indexHandler{
|
||||||
@@ -133,7 +139,7 @@ func newIndexHandler(conn protocol.Connection, downloads *deviceDownloadState, f
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// waitWhilePaused waits for the handler to resume
|
// waitWhilePaused waits for the handler to resume.
|
||||||
func (s *indexHandler) waitWhilePaused(ctx context.Context) error {
|
func (s *indexHandler) waitWhilePaused(ctx context.Context) error {
|
||||||
s.cond.L.Lock()
|
s.cond.L.Lock()
|
||||||
defer s.cond.L.Unlock()
|
defer s.cond.L.Unlock()
|
||||||
|
|||||||
+3
-3
@@ -372,7 +372,7 @@ func (m *model) addAndStartFolderLockedWithIgnores(cfg config.FolderConfiguratio
|
|||||||
for _, available := range devs {
|
for _, available := range devs {
|
||||||
if _, ok := expected[available]; !ok {
|
if _, ok := expected[available]; !ok {
|
||||||
l.Debugln("dropping", folder, "state for", available)
|
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()
|
m.mut.Unlock()
|
||||||
|
|
||||||
// Remove it from the database
|
// 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.
|
// Need to hold lock on m.mut when calling this.
|
||||||
@@ -1559,7 +1559,7 @@ func (m *model) ccCheckEncryption(fcfg config.FolderConfiguration, folderDevice
|
|||||||
|
|
||||||
if isEncryptedRemote {
|
if isEncryptedRemote {
|
||||||
passwordToken := protocol.PasswordToken(m.keyGen, fcfg.ID, folderDevice.EncryptionPassword)
|
passwordToken := protocol.PasswordToken(m.keyGen, fcfg.ID, folderDevice.EncryptionPassword)
|
||||||
match := false
|
var match bool
|
||||||
if hasTokenLocal {
|
if hasTokenLocal {
|
||||||
match = bytes.Equal(passwordToken, ccDeviceInfos.local.EncryptionPasswordToken)
|
match = bytes.Equal(passwordToken, ccDeviceInfos.local.EncryptionPasswordToken)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ func (s *sentFolderDownloadState) update(pullers []*sharedPullerState) []protoco
|
|||||||
localFile.updated = pullerBlockIndexesUpdated
|
localFile.updated = pullerBlockIndexesUpdated
|
||||||
localFile.version = pullerVersion
|
localFile.version = pullerVersion
|
||||||
localFile.created = pullerCreated
|
localFile.created = pullerCreated
|
||||||
localFile.blockSize = int(pullerBlockSize)
|
localFile.blockSize = pullerBlockSize
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ package model
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -16,7 +17,7 @@ import (
|
|||||||
"github.com/thejerf/suture/v4"
|
"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
|
// 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
|
// 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 {
|
if tok, ok := s.tokens[k]; ok {
|
||||||
s.supervisor.Remove(tok)
|
s.supervisor.Remove(tok)
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// StopAndWaitChan removes the service at the given key from the supervisor,
|
// StopAndWaitChan removes the service at the given key from the supervisor,
|
||||||
|
|||||||
Reference in New Issue
Block a user