chore: style fixes from go fix (#10846)

Just `go fix ./...`

Signed-off-by: Jakob Borg <jakob@kastelo.net>
This commit is contained in:
Jakob Borg
2026-08-05 20:23:22 +02:00
committed by GitHub
parent 946e2b83a1
commit 8ea09c0094
144 changed files with 211 additions and 315 deletions
+2 -5
View File
@@ -47,7 +47,7 @@ func (randomOrderBlockPullReorderer) Reorder(blocks []protocol.BlockInfo) []prot
type standardBlockPullReorderer struct {
myIndex int
count int
shuffle func(interface{}) // Used for test
shuffle func(any) // Used for test
}
func newStandardBlockPullReorderer(id protocol.DeviceID, otherDevices []protocol.DeviceID) *standardBlockPullReorderer {
@@ -116,10 +116,7 @@ func chunk(blocks []protocol.BlockInfo, partCount int) [][]protocol.BlockInfo {
chunkSize := (count + partCount - 1) / partCount
parts := make([][]protocol.BlockInfo, 0, partCount)
for i := 0; i < count; i += chunkSize {
end := i + chunkSize
if end > count {
end = count
}
end := min(i+chunkSize, count)
parts = append(parts, blocks[i:end])
}
return parts
+1 -1
View File
@@ -92,7 +92,7 @@ func Test_standardBlockPullReorderer_Reorder(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := newStandardBlockPullReorderer(tt.myId, tt.devices)
p.shuffle = func(i interface{}) {} // Noop shuffle
p.shuffle = func(i any) {} // Noop shuffle
if got := p.Reorder(tt.blocks); !reflect.DeepEqual(got, tt.want) {
t.Errorf("reorderBlocksForDevices() = %v, want %v (my idx: %d, count %d)", got, tt.want, p.myIndex, p.count)
}
+2 -2
View File
@@ -1164,7 +1164,7 @@ func (f *folder) setWatchError(err error, nextTryIn time.Duration) {
f.watchErr = err
f.watchMut.Unlock()
if err != prevErr { //nolint:errorlint
data := map[string]interface{}{
data := map[string]any{
"folder": f.ID,
}
if prevErr != nil {
@@ -1338,7 +1338,7 @@ func (f *folder) updateLocals(fs []protocol.FileInfo) error {
if err != nil {
return err
}
f.evLogger.Log(events.LocalIndexUpdated, map[string]interface{}{
f.evLogger.Log(events.LocalIndexUpdated, map[string]any{
"folder": f.ID,
"items": len(fs),
"filenames": filenames,
+9 -9
View File
@@ -229,7 +229,7 @@ func (f *sendReceiveFolder) pull(ctx context.Context) (bool, error) {
f.errorsMut.Unlock()
if pullErrNum > 0 {
f.evLogger.Log(events.FolderErrors, map[string]interface{}{
f.evLogger.Log(events.FolderErrors, map[string]any{
"folder": f.folderID,
"errors": f.Errors(),
})
@@ -564,7 +564,7 @@ func (f *sendReceiveFolder) handleDir(file protocol.FileInfo, dbUpdateChan chan<
defer func() {
slog.Info("Created or updated directory", f.LogAttr(), file.LogAttr())
f.evLogger.Log(events.ItemFinished, map[string]interface{}{
f.evLogger.Log(events.ItemFinished, map[string]any{
"folder": f.folderID,
"item": file.Name,
"error": events.Error(err),
@@ -737,7 +737,7 @@ func (f *sendReceiveFolder) handleSymlink(file protocol.FileInfo, dbUpdateChan c
} else {
slog.Info("Created or updated symlink", f.LogAttr(), file.LogAttr())
}
f.evLogger.Log(events.ItemFinished, map[string]interface{}{
f.evLogger.Log(events.ItemFinished, map[string]any{
"folder": f.folderID,
"item": file.Name,
"error": events.Error(err),
@@ -832,7 +832,7 @@ func (f *sendReceiveFolder) deleteDir(file protocol.FileInfo, dbUpdateChan chan<
} else {
slog.Info("Deleted directory", f.LogAttr(), file.LogAttr())
}
f.evLogger.Log(events.ItemFinished, map[string]interface{}{
f.evLogger.Log(events.ItemFinished, map[string]any{
"folder": f.folderID,
"item": file.Name,
"error": events.Error(err),
@@ -896,7 +896,7 @@ func (f *sendReceiveFolder) deleteFileWithCurrent(file, cur protocol.FileInfo, h
} else {
slog.Info("Deleted "+kind, f.LogAttr(), file.LogAttr())
}
f.evLogger.Log(events.ItemFinished, map[string]interface{}{
f.evLogger.Log(events.ItemFinished, map[string]any{
"folder": f.folderID,
"item": file.Name,
"error": events.Error(err),
@@ -981,14 +981,14 @@ func (f *sendReceiveFolder) renameFile(cur, source, target protocol.FileInfo, db
} else {
slog.Info("Renamed file", f.LogAttr(), target.LogAttr(), slog.String("from", source.Name))
}
f.evLogger.Log(events.ItemFinished, map[string]interface{}{
f.evLogger.Log(events.ItemFinished, map[string]any{
"folder": f.folderID,
"item": source.Name,
"error": events.Error(err),
"type": "file",
"action": "delete",
})
f.evLogger.Log(events.ItemFinished, map[string]interface{}{
f.evLogger.Log(events.ItemFinished, map[string]any{
"folder": f.folderID,
"item": target.Name,
"error": events.Error(err),
@@ -1275,7 +1275,7 @@ func (f *sendReceiveFolder) shortcutFile(file protocol.FileInfo, dbUpdateChan ch
} else {
slog.Info("Updated file metadata", f.LogAttr(), file.LogAttr())
}
f.evLogger.Log(events.ItemFinished, map[string]interface{}{
f.evLogger.Log(events.ItemFinished, map[string]any{
"folder": f.folderID,
"item": file.Name,
"error": events.Error(err),
@@ -1748,7 +1748,7 @@ func (f *sendReceiveFolder) finisherRoutine(ctx context.Context, in <-chan *shar
f.model.progressEmitter.Deregister(state)
}
f.evLogger.Log(events.ItemFinished, map[string]interface{}{
f.evLogger.Log(events.ItemFinished, map[string]any{
"folder": f.folderID,
"item": state.file.Name,
"error": events.Error(err),
+4 -4
View File
@@ -251,7 +251,7 @@ func TestCopierFinder(t *testing.T) {
timeout := time.After(10 * time.Second)
pulls := make([]pullBlockState, 4)
for i := 0; i < 4; i++ {
for i := range 4 {
select {
case pulls[i] = <-pullChan:
case <-timeout:
@@ -408,7 +408,7 @@ func TestDeregisterOnFailInCopy(t *testing.T) {
t0 := time.Now()
if ev, err := s.Poll(time.Minute); err != nil {
t.Fatal("Got error waiting for ItemFinished event:", err)
} else if n := ev.Data.(map[string]interface{})["item"]; n != state.file.Name {
} else if n := ev.Data.(map[string]any)["item"]; n != state.file.Name {
t.Fatal("Got ItemFinished event for wrong file:", n)
}
t.Log("event took", time.Since(t0))
@@ -513,7 +513,7 @@ func TestDeregisterOnFailInPull(t *testing.T) {
t0 := time.Now()
if ev, err := s.Poll(time.Minute); err != nil {
t.Fatal("Got error waiting for ItemFinished event:", err)
} else if n := ev.Data.(map[string]interface{})["item"]; n != state.file.Name {
} else if n := ev.Data.(map[string]any)["item"]; n != state.file.Name {
t.Fatal("Got ItemFinished event for wrong file:", n)
}
t.Log("event took", time.Since(t0))
@@ -899,7 +899,7 @@ func TestPullCtxCancel(t *testing.T) {
done := make(chan struct{})
defer close(done)
for i := 0; i < 2; i++ {
for i := range 2 {
go func() {
select {
case pullChan <- emptyState():
-1
View File
@@ -5,7 +5,6 @@
// You can obtain one at https://mozilla.org/MPL/2.0/.
//go:build !windows
// +build !windows
package model
+2 -2
View File
@@ -265,7 +265,7 @@ func (c *folderSummaryService) processUpdate(ev events.Event) {
return
case events.StateChanged:
data := ev.Data.(map[string]interface{})
data := ev.Data.(map[string]any)
if data["to"].(string) != "idle" {
return
}
@@ -296,7 +296,7 @@ func (c *folderSummaryService) processUpdate(ev events.Event) {
// This folder needs to be refreshed whenever we do the next
// refresh.
folder = ev.Data.(map[string]interface{})["folder"].(string)
folder = ev.Data.(map[string]any)["folder"].(string)
}
c.foldersMut.Lock()
+2 -2
View File
@@ -119,7 +119,7 @@ func (s *stateTracker) setState(newState folderState) {
metricFolderState.WithLabelValues(s.folderID).Set(float64(s.current))
}()
eventData := map[string]interface{}{
eventData := map[string]any{
"folder": s.folderID,
"to": newState.String(),
"from": s.current.String(),
@@ -156,7 +156,7 @@ func (s *stateTracker) setError(err error) {
metricFolderState.WithLabelValues(s.folderID).Set(float64(s.current))
}()
eventData := map[string]interface{}{
eventData := map[string]any{
"folder": s.folderID,
"from": s.current.String(),
}
+1 -1
View File
@@ -453,7 +453,7 @@ func (s *indexHandler) receive(fs []protocol.FileInfo, update bool, op string, p
})
}
s.evLogger.Log(events.RemoteIndexUpdated, map[string]interface{}{
s.evLogger.Log(events.RemoteIndexUpdated, map[string]any{
"device": deviceID.String(),
"folder": s.folder,
"items": len(fs),
+4 -6
View File
@@ -7,7 +7,6 @@
package model_test
import (
"context"
"fmt"
"io"
"sync"
@@ -23,8 +22,7 @@ import (
func TestIndexhandlerConcurrency(t *testing.T) {
// Verify that sending a lot of index update messages using the
// FileInfoBatch works and doesn't trigger the race detector.
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()
ar, aw := io.Pipe()
br, bw := io.Pipe()
@@ -52,7 +50,7 @@ func TestIndexhandlerConcurrency(t *testing.T) {
recvdBatches := 0
var wg sync.WaitGroup
m2.IndexUpdateCalls(func(_ protocol.Connection, idxUp *protocol.IndexUpdate) error {
for j := 0; j < files; j++ {
for j := range int(files) {
if n := idxUp.Files[j].Name; n != fmt.Sprintf("f%d-%d", recvdBatches, j) {
t.Error("wrong filename", n)
}
@@ -67,8 +65,8 @@ func TestIndexhandlerConcurrency(t *testing.T) {
return c1.IndexUpdate(ctx, &protocol.IndexUpdate{Folder: "foo", Files: fs})
})
sentEntries := 0
for i := 0; i < msgs; i++ {
for j := 0; j < files; j++ {
for i := range int(msgs) {
for j := range int(files) {
b1.Append(protocol.FileInfo{
Name: fmt.Sprintf("f%d-%d", i, j),
Blocks: []protocol.BlockInfo{{Hash: make([]byte, 32)}},
+15 -15
View File
@@ -116,7 +116,7 @@ type Model interface {
Availability(folder string, file protocol.FileInfo, block protocol.BlockInfo) ([]Availability, error)
Completion(device protocol.DeviceID, folder string) (FolderCompletion, error)
ConnectionStats() map[string]interface{}
ConnectionStats() map[string]any
DeviceStatistics() (map[protocol.DeviceID]stats.DeviceStatistics, error)
FolderStatistics() (map[string]stats.FolderStatistics, error)
UsageReportingStats(report *contract.Report, version int, preview bool)
@@ -684,7 +684,7 @@ type ConnectionStats struct {
IsLocal bool `json:"isLocal"` // mirror values from Primary, for compatibility with <1.24.0
Crypto string `json:"crypto"` // mirror values from Primary, for compatibility with <1.24.0
Primary ConnectionInfo `json:"primary,omitempty"`
Primary ConnectionInfo `json:"primary"`
Secondary []ConnectionInfo `json:"secondary,omitempty"`
}
@@ -698,11 +698,11 @@ type ConnectionInfo struct {
}
// ConnectionStats returns a map with connection statistics for each device.
func (m *model) ConnectionStats() map[string]interface{} {
func (m *model) ConnectionStats() map[string]any {
m.mut.RLock()
defer m.mut.RUnlock()
res := make(map[string]interface{})
res := make(map[string]any)
devs := m.cfg.Devices()
conns := make(map[string]ConnectionStats, len(devs))
for device, deviceCfg := range devs {
@@ -762,7 +762,7 @@ func (m *model) ConnectionStats() map[string]interface{} {
res["connections"] = conns
in, out := protocol.TotalInOut()
res["total"] = map[string]interface{}{
res["total"] = map[string]any{
"at": time.Now().Truncate(time.Second),
"inBytesTotal": in,
"outBytesTotal": out,
@@ -862,8 +862,8 @@ func (comp *FolderCompletion) setCompletionPct() {
}
// Map returns the members as a map, e.g. used in api to serialize as JSON.
func (comp *FolderCompletion) Map() map[string]interface{} {
return map[string]interface{}{
func (comp *FolderCompletion) Map() map[string]any {
return map[string]any{
"completion": comp.CompletionPct,
"globalBytes": comp.GlobalBytes,
"needBytes": comp.NeedBytes,
@@ -1516,7 +1516,7 @@ func (m *model) ccHandleFolders(folders []protocol.Folder, deviceCfg config.Devi
})
}
if len(updatedPending) > 0 || len(expiredPendingList) > 0 {
m.evLogger.Log(events.PendingFoldersChanged, map[string]interface{}{
m.evLogger.Log(events.PendingFoldersChanged, map[string]any{
"added": updatedPending,
"removed": expiredPendingList,
})
@@ -2266,7 +2266,7 @@ func (m *model) OnHello(remoteID protocol.DeviceID, addr net.Addr, hello protoco
if err := m.observed.AddOrUpdatePendingDevice(remoteID, hello.DeviceName, addr.String()); err != nil {
slog.Warn("Failed to persist pending device entry to database", slogutil.Error(err))
}
m.evLogger.Log(events.PendingDevicesChanged, map[string][]interface{}{
m.evLogger.Log(events.PendingDevicesChanged, map[string][]any{
"added": {map[string]string{
"deviceID": remoteID.String(),
"name": hello.DeviceName,
@@ -2426,7 +2426,7 @@ func (m *model) DownloadProgress(conn protocol.Connection, p *protocol.DownloadP
downloads.Update(p.Folder, p.Updates)
state := downloads.GetBlockCounts(p.Folder)
m.evLogger.Log(events.RemoteDownloadProgress, map[string]interface{}{
m.evLogger.Log(events.RemoteDownloadProgress, map[string]any{
"device": deviceID.String(),
"folder": p.Folder,
"state": state,
@@ -2772,7 +2772,7 @@ func (m *model) GlobalDirectoryTree(folder, prefix string, levels int, dirsOnly
parent := root
if dir != "." {
for _, path := range strings.Split(dir, sep) {
for path := range strings.SplitSeq(dir, sep) {
child := findByName(parent.Children, path)
if child == nil {
return nil, fmt.Errorf("could not find child '%s' for path '%s' in parent '%s'", path, f.Name, parent.Name)
@@ -3183,7 +3183,7 @@ func (m *model) cleanPending(existingDevices map[protocol.DeviceID]config.Device
}
}
if len(removedPendingFolders) > 0 {
m.evLogger.Log(events.PendingFoldersChanged, map[string]interface{}{
m.evLogger.Log(events.PendingFoldersChanged, map[string]any{
"removed": removedPendingFolders,
})
}
@@ -3218,7 +3218,7 @@ func (m *model) cleanPending(existingDevices map[protocol.DeviceID]config.Device
})
}
if len(removedPendingDevices) > 0 {
m.evLogger.Log(events.PendingDevicesChanged, map[string]interface{}{
m.evLogger.Log(events.PendingDevicesChanged, map[string]any{
"removed": removedPendingDevices,
})
}
@@ -3264,7 +3264,7 @@ func (m *model) DismissPendingDevice(device protocol.DeviceID) error {
removedPendingDevices := []map[string]string{
{"deviceID": device.String()},
}
m.evLogger.Log(events.PendingDevicesChanged, map[string]interface{}{
m.evLogger.Log(events.PendingDevicesChanged, map[string]any{
"removed": removedPendingDevices,
})
return nil
@@ -3298,7 +3298,7 @@ func (m *model) DismissPendingFolder(device protocol.DeviceID, folder string) er
}
}
if len(removedPendingFolders) > 0 {
m.evLogger.Log(events.PendingFoldersChanged, map[string]interface{}{
m.evLogger.Log(events.PendingFoldersChanged, map[string]any{
"removed": removedPendingFolders,
})
}
+8 -8
View File
@@ -151,7 +151,7 @@ func TestRequest(t *testing.T) {
func genFiles(n int) []protocol.FileInfo {
files := make([]protocol.FileInfo, n)
t := time.Now().Unix()
for i := 0; i < n; i++ {
for i := range n {
files[i] = protocol.FileInfo{
Name: fmt.Sprintf("file%d", i),
ModifiedS: t,
@@ -1007,7 +1007,7 @@ func TestIssue5063(t *testing.T) {
reps := 10
ids := make([]string, reps)
for i := 0; i < reps; i++ {
for i := range reps {
ids[i] = srand.String(8)
wg.Go(func() { addAndVerify(ids[i]) })
}
@@ -1668,7 +1668,7 @@ func waitForState(t *testing.T, sub events.Subscription, folder, expected string
for {
select {
case ev := <-sub.C():
data := ev.Data.(map[string]interface{})
data := ev.Data.(map[string]any)
if data["folder"].(string) == folder {
if data["error"] == nil {
err = ""
@@ -1880,7 +1880,7 @@ func TestGlobalDirectoryTree(t *testing.T) {
f("zzrootfile"),
}
mm := func(data interface{}) string {
mm := func(data any) string {
bytes, err := json.MarshalIndent(data, "", " ")
if err != nil {
panic(err)
@@ -2952,7 +2952,7 @@ func TestFolderRestartZombies(t *testing.T) {
// Run a few parallel configuration changers for one second. Each waits
// for the commit to complete, but there are many of them.
var wg sync.WaitGroup
for i := 0; i < 25; i++ {
for range 25 {
wg.Go(func() {
t0 := time.Now()
for time.Since(t0) < time.Second {
@@ -3258,7 +3258,7 @@ func TestRenameSequenceOrder(t *testing.T) {
numFiles := 20
ffs := fcfg.Filesystem()
for i := 0; i < numFiles; i++ {
for i := range numFiles {
v := fmt.Sprintf("%d", i)
writeFile(t, ffs, v, []byte(v))
}
@@ -3272,7 +3272,7 @@ func TestRenameSequenceOrder(t *testing.T) {
// Modify all the files other than the rename sources, whose content we
// keep intact so the renamed copies still match by block hash.
for i := 0; i < numFiles; i++ {
for i := range numFiles {
if i == 3 || i == 16 {
continue
}
@@ -3388,7 +3388,7 @@ func TestRenameBatchFlush(t *testing.T) {
writeFile(t, ffs, "dst-a", content)
writeFile(t, ffs, "dst-b", content)
for i := range MaxBatchSizeFiles * 2 {
writeFile(t, ffs, fmt.Sprintf("filler-%04d", i), []byte(fmt.Sprintf("filler-%04d", i)))
writeFile(t, ffs, fmt.Sprintf("filler-%04d", i), fmt.Appendf(nil, "filler-%04d", i))
}
m.ScanFolders()
+1 -1
View File
@@ -200,7 +200,7 @@ func TestQueuePagination(t *testing.T) {
q := newJobQueue()
// Ten random actions
names := make([]string, 10)
for i := 0; i < 10; i++ {
for i := range 10 {
names[i] = fmt.Sprint("f", i)
q.Push(names[i], 0, time.Time{})
}
+2 -2
View File
@@ -582,7 +582,7 @@ func TestRequestSymlinkWindows(t *testing.T) {
for {
select {
case ev := <-sub.C():
switch data := ev.Data.(map[string]interface{}); {
switch data := ev.Data.(map[string]any); {
case ev.Type == events.LocalIndexUpdated:
t.Fatalf("Local index was updated unexpectedly: %v", data)
case ev.Type == events.StateChanged:
@@ -927,7 +927,7 @@ func TestNeedFolderFiles(t *testing.T) {
data := []byte("foo")
num := 20
for i := 0; i < num; i++ {
for i := range num {
fc.addFile(strconv.Itoa(i), 0o644, protocol.FileInfoTypeFile, data)
}
fc.sendIndexUpdate()
+1 -1
View File
@@ -8,7 +8,7 @@ package model
// fatal is the required common interface between *testing.B and *testing.T
type fatal interface {
Fatal(...interface{})
Fatal(...any)
Helper()
}
+1 -1
View File
@@ -284,7 +284,7 @@ func localIndexUpdate(m *testModel, folder string, fs []protocol.FileInfo) {
for i, file := range fs {
filenames[i] = file.Name
}
m.evLogger.Log(events.LocalIndexUpdated, map[string]interface{}{
m.evLogger.Log(events.LocalIndexUpdated, map[string]any{
"folder": folder,
"items": len(fs),
"filenames": filenames,