mirror of
https://github.com/restic/restic.git
synced 2026-09-01 02:07:14 +00:00
Apply go fix ./... (#22037)
This commit is contained in:
@@ -205,10 +205,10 @@ func TestConcurrencyUnlimitedLockSave(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFreeze(t *testing.T) {
|
||||
var counter int64
|
||||
var counter atomic.Int64
|
||||
m := mock.NewBackend()
|
||||
m.SaveFn = func(ctx context.Context, h backend.Handle, rd backend.RewindReader) error {
|
||||
atomic.AddInt64(&counter, 1)
|
||||
counter.Add(1)
|
||||
return nil
|
||||
}
|
||||
m.PropertiesFn = func() backend.Properties {
|
||||
@@ -232,12 +232,12 @@ func TestFreeze(t *testing.T) {
|
||||
|
||||
// check
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
val := atomic.LoadInt64(&counter)
|
||||
val := counter.Load()
|
||||
test.Assert(t, val == 0, "save call worked despite frozen backend")
|
||||
|
||||
// unfreeze and check that save did complete
|
||||
fb.Unfreeze()
|
||||
wg.Wait()
|
||||
val = atomic.LoadInt64(&counter)
|
||||
val = counter.Load()
|
||||
test.Assert(t, val == 1, "save call should have completed")
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ var genericAttributesForOS = map[GenericAttributeType]osType{}
|
||||
func storeGenericAttributeType(attributeTypes ...GenericAttributeType) {
|
||||
for _, attributeType := range attributeTypes {
|
||||
// Get the OS attribute type from the GenericAttributeType
|
||||
osAttributeName := strings.Split(string(attributeType), ".")[0]
|
||||
osAttributeName, _, _ := strings.Cut(string(attributeType), ".")
|
||||
genericAttributesForOS[attributeType] = osType(osAttributeName)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package data
|
||||
import (
|
||||
"context"
|
||||
"runtime"
|
||||
"slices"
|
||||
"sync"
|
||||
|
||||
"github.com/restic/restic/internal/debug"
|
||||
@@ -158,8 +159,8 @@ func filterTrees(ctx context.Context, repo restic.Loader, trees restic.IDs, load
|
||||
|
||||
debug.Log("input job tree %v", j.ID)
|
||||
// iterate backwards over subtree to compensate backwards traversal order of nextTreeID selection
|
||||
for i := len(j.Subtrees) - 1; i >= 0; i-- {
|
||||
id := j.Subtrees[i]
|
||||
for _, id := range slices.Backward(j.Subtrees) {
|
||||
|
||||
if id.IsNull() {
|
||||
// We do not need to raise this error here, it is
|
||||
// checked when the tree is checked. Just make sure
|
||||
|
||||
@@ -3,6 +3,7 @@ package errors
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
)
|
||||
|
||||
// fatalError is an error that should be printed to the user, then the program
|
||||
@@ -36,8 +37,8 @@ func Fatal(s string) error {
|
||||
func Fatalf(s string, data ...any) error {
|
||||
// Use the last error found.
|
||||
var underlyingErr error
|
||||
for i := len(data) - 1; i >= 0; i-- {
|
||||
if err, ok := data[i].(error); ok {
|
||||
for _, d := range slices.Backward(data) {
|
||||
if err, ok := d.(error); ok {
|
||||
underlyingErr = err
|
||||
break
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package filter
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/restic/restic/internal/errors"
|
||||
@@ -195,12 +196,12 @@ func match(pattern Pattern, strs []string) (matched bool, err error) {
|
||||
outer:
|
||||
for offset := maxOffset; offset >= minOffset; offset-- {
|
||||
|
||||
for i := len(pattern.parts) - 1; i >= 0; i-- {
|
||||
for i, v := range slices.Backward(pattern.parts) {
|
||||
var ok bool
|
||||
if pattern.parts[i].isSimple {
|
||||
ok = pattern.parts[i].pattern == strs[offset+i]
|
||||
if v.isSimple {
|
||||
ok = v.pattern == strs[offset+i]
|
||||
} else {
|
||||
ok, err = filepath.Match(pattern.parts[i].pattern, strs[offset+i])
|
||||
ok, err = filepath.Match(v.pattern, strs[offset+i])
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "Match")
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/restic/restic/internal/data"
|
||||
@@ -542,8 +543,8 @@ func (res *Restorer) removeUnexpectedFiles(ctx context.Context, target, location
|
||||
}
|
||||
|
||||
// Report paths as deleted only after successful removal
|
||||
for i := len(filesToDelete) - 1; i >= 0; i-- {
|
||||
res.opts.Progress.ReportDeletion(filesToDelete[i])
|
||||
for _, f := range slices.Backward(filesToDelete) {
|
||||
res.opts.Progress.ReportDeletion(f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user