mirror of
https://github.com/restic/restic.git
synced 2026-08-06 05:33:17 +00:00
Merge pull request #21978 from MichaelEischer/go-fix2
Run `go fix ./...`
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -181,7 +182,7 @@ var ErrNoSourceData = errors.Fatal("all source directories/files do not exist")
|
||||
|
||||
// filterExisting returns the items that exist and can be accessed. It returns
|
||||
// ErrNoSourceData if none remain, or ErrInvalidSourceData if some were skipped.
|
||||
func filterExisting(items []string, warnf func(msg string, args ...interface{})) (result []string, err error) {
|
||||
func filterExisting(items []string, warnf func(msg string, args ...any)) (result []string, err error) {
|
||||
for _, item := range items {
|
||||
_, err := fs.Lstat(item)
|
||||
if err != nil {
|
||||
@@ -304,10 +305,8 @@ func (opts BackupOptions) Check(gopts global.Options, args []string) error {
|
||||
}
|
||||
|
||||
filesFrom := append(append(opts.FilesFrom, opts.FilesFromVerbatim...), opts.FilesFromRaw...)
|
||||
for _, filename := range filesFrom {
|
||||
if filename == "-" {
|
||||
return errors.Fatal("unable to read password from stdin when data is to be read from stdin, use --password-file or $RESTIC_PASSWORD")
|
||||
}
|
||||
if slices.Contains(filesFrom, "-") {
|
||||
return errors.Fatal("unable to read password from stdin when data is to be read from stdin, use --password-file or $RESTIC_PASSWORD")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -332,7 +331,7 @@ func (opts BackupOptions) Check(gopts global.Options, args []string) error {
|
||||
|
||||
// collectRejectByNameFuncs returns a list of all functions which may reject data
|
||||
// from being saved in a snapshot based on path only
|
||||
func collectRejectByNameFuncs(opts BackupOptions, repo *repository.Repository, warnf func(msg string, args ...interface{})) (fs []archiver.RejectByNameFunc, err error) {
|
||||
func collectRejectByNameFuncs(opts BackupOptions, repo *repository.Repository, warnf func(msg string, args ...any)) (fs []archiver.RejectByNameFunc, err error) {
|
||||
// exclude restic cache
|
||||
if repo.Cache() != nil {
|
||||
f, err := rejectResticCache(repo)
|
||||
@@ -356,7 +355,7 @@ func collectRejectByNameFuncs(opts BackupOptions, repo *repository.Repository, w
|
||||
|
||||
// collectRejectFuncs returns a list of all functions which may reject data
|
||||
// from being saved in a snapshot based on path and file info
|
||||
func collectRejectFuncs(opts BackupOptions, targets []string, fs fs.FS, warnf func(msg string, args ...interface{})) (funcs []archiver.RejectFunc, err error) {
|
||||
func collectRejectFuncs(opts BackupOptions, targets []string, fs fs.FS, warnf func(msg string, args ...any)) (funcs []archiver.RejectFunc, err error) {
|
||||
// allowed devices
|
||||
if opts.ExcludeOtherFS && !opts.Stdin && !opts.StdinCommand {
|
||||
f, err := archiver.RejectByDevice(targets, fs)
|
||||
@@ -404,7 +403,7 @@ func collectRejectFuncs(opts BackupOptions, targets []string, fs fs.FS, warnf fu
|
||||
}
|
||||
|
||||
// collectTargets returns a list of target files/dirs from several sources.
|
||||
func collectTargets(opts BackupOptions, args []string, warnf func(msg string, args ...interface{}), stdin io.ReadCloser) (targets []string, err error) {
|
||||
func collectTargets(opts BackupOptions, args []string, warnf func(msg string, args ...any), stdin io.ReadCloser) (targets []string, err error) {
|
||||
if opts.Stdin || opts.StdinCommand {
|
||||
return nil, nil
|
||||
}
|
||||
@@ -589,7 +588,7 @@ func runBackup(ctx context.Context, opts BackupOptions, gopts global.Options, te
|
||||
_ = progressReporter.Error(item, err)
|
||||
}
|
||||
|
||||
messageHandler := func(msg string, args ...interface{}) {
|
||||
messageHandler := func(msg string, args ...any) {
|
||||
if !gopts.JSON {
|
||||
printer.P(msg, args...)
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -154,7 +155,7 @@ func (f *vssDeleteOriginalFS) Lstat(name string) (*fs.ExtendedFileInfo, error) {
|
||||
_, _ = f.FS.Lstat(name)
|
||||
// nuke testdata
|
||||
var err error
|
||||
for i := 0; i < 3; i++ {
|
||||
for range 3 {
|
||||
// The CI sometimes runs into "The process cannot access the file because it is being used by another process" errors
|
||||
// thus try a few times to remove the data
|
||||
err = os.RemoveAll(f.testdata)
|
||||
@@ -630,13 +631,7 @@ func linkEqual(source, dest []string) bool {
|
||||
}
|
||||
|
||||
for i := range source {
|
||||
found := false
|
||||
for j := range dest {
|
||||
if source[i] == dest[j] {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
found := slices.Contains(dest, source[i])
|
||||
if !found {
|
||||
return false
|
||||
}
|
||||
@@ -738,7 +733,7 @@ func TestBackupSkipIfUnchanged(t *testing.T) {
|
||||
testSetupBackupData(t, env)
|
||||
opts := BackupOptions{SkipIfUnchanged: true}
|
||||
|
||||
for i := 0; i < 3; i++ {
|
||||
for range 3 {
|
||||
testRunBackup(t, filepath.Dir(env.testdata), []string{"testdata"}, opts, env.gopts)
|
||||
testListSnapshots(t, env.gopts, 1)
|
||||
}
|
||||
@@ -760,7 +755,7 @@ func TestBackupExcludeWithOutput(t *testing.T) {
|
||||
rtest.OK(t, err)
|
||||
|
||||
foundExclude := false
|
||||
for _, line := range bytes.Split(output, []byte("\n")) {
|
||||
for line := range bytes.SplitSeq(output, []byte("\n")) {
|
||||
if len(line) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@@ -49,13 +50,7 @@ func validateCatArgs(args []string) error {
|
||||
return errors.Fatal("type not specified")
|
||||
}
|
||||
|
||||
validType := false
|
||||
for _, v := range catAllowedCmds {
|
||||
if v == args[0] {
|
||||
validType = true
|
||||
break
|
||||
}
|
||||
}
|
||||
validType := slices.Contains(catAllowedCmds, args[0])
|
||||
if !validType {
|
||||
return errors.Fatalf("invalid type %q, must be one of [%s]", args[0], strings.Join(catAllowedCmds, "|"))
|
||||
}
|
||||
|
||||
+8
-10
@@ -342,13 +342,11 @@ func runCheck(ctx context.Context, opts CheckOptions, gopts global.Options, args
|
||||
var brokenSnapshots []string
|
||||
var wg sync.WaitGroup
|
||||
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
wg.Go(func() {
|
||||
bar := printer.NewCounter("snapshots")
|
||||
defer bar.Done()
|
||||
chkr.Structure(ctx, bar, errChan)
|
||||
}()
|
||||
})
|
||||
|
||||
for err := range errChan {
|
||||
errorsFound = true
|
||||
@@ -570,15 +568,15 @@ func (*jsonErrorPrinter) NewCounterTerminalOnly(_ string) restic.Counter {
|
||||
return restic.NoopCounter
|
||||
}
|
||||
|
||||
func (p *jsonErrorPrinter) E(msg string, args ...interface{}) {
|
||||
func (p *jsonErrorPrinter) E(msg string, args ...any) {
|
||||
status := checkError{
|
||||
MessageType: "error",
|
||||
Message: fmt.Sprintf(msg, args...),
|
||||
}
|
||||
p.term.Error(ui.ToJSONString(status))
|
||||
}
|
||||
func (*jsonErrorPrinter) S(_ string, _ ...interface{}) {}
|
||||
func (*jsonErrorPrinter) P(_ string, _ ...interface{}) {}
|
||||
func (*jsonErrorPrinter) PT(_ string, _ ...interface{}) {}
|
||||
func (*jsonErrorPrinter) V(_ string, _ ...interface{}) {}
|
||||
func (*jsonErrorPrinter) VV(_ string, _ ...interface{}) {}
|
||||
func (*jsonErrorPrinter) S(_ string, _ ...any) {}
|
||||
func (*jsonErrorPrinter) P(_ string, _ ...any) {}
|
||||
func (*jsonErrorPrinter) PT(_ string, _ ...any) {}
|
||||
func (*jsonErrorPrinter) V(_ string, _ ...any) {}
|
||||
func (*jsonErrorPrinter) VV(_ string, _ ...any) {}
|
||||
|
||||
@@ -84,7 +84,7 @@ type Comparer struct {
|
||||
repo restic.BlobLoader
|
||||
opts DiffOptions
|
||||
printChange func(change *Change)
|
||||
printError func(string, ...interface{})
|
||||
printError func(string, ...any)
|
||||
}
|
||||
|
||||
type Change struct {
|
||||
@@ -158,7 +158,7 @@ type DiffStatsContainer struct {
|
||||
}
|
||||
|
||||
// updateBlobs updates the blob counters in the stats struct.
|
||||
func updateBlobs(repo restic.Loader, blobs restic.AssociatedBlobSet, stats *DiffStat, printError func(string, ...interface{})) {
|
||||
func updateBlobs(repo restic.Loader, blobs restic.AssociatedBlobSet, stats *DiffStat, printError func(string, ...any)) {
|
||||
for h := range blobs.Keys() {
|
||||
switch h.Type {
|
||||
case restic.DataBlob:
|
||||
|
||||
@@ -136,9 +136,9 @@ type statefulOutput struct {
|
||||
oldsn *data.Snapshot
|
||||
hits int
|
||||
printer interface {
|
||||
S(string, ...interface{})
|
||||
P(string, ...interface{})
|
||||
E(string, ...interface{})
|
||||
S(string, ...any)
|
||||
P(string, ...any)
|
||||
E(string, ...any)
|
||||
}
|
||||
stdout io.Writer
|
||||
}
|
||||
@@ -214,7 +214,7 @@ func (s *statefulOutput) PrintObjectJSON(kind, id, nodepath, treeID string, sn *
|
||||
Path string `json:"path"`
|
||||
ParentTree string `json:"parent_tree,omitempty"`
|
||||
SnapshotID string `json:"snapshot"`
|
||||
Time time.Time `json:"time,omitempty"`
|
||||
Time time.Time `json:"time"`
|
||||
}{
|
||||
ObjectType: kind,
|
||||
ID: id,
|
||||
@@ -281,9 +281,9 @@ type Finder struct {
|
||||
treeIDs map[string]struct{}
|
||||
itemsFound int
|
||||
printer interface {
|
||||
S(string, ...interface{})
|
||||
P(string, ...interface{})
|
||||
E(string, ...interface{})
|
||||
S(string, ...any)
|
||||
P(string, ...any)
|
||||
E(string, ...any)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ type testMatch struct {
|
||||
Path string `json:"path,omitempty"`
|
||||
Permissions string `json:"permissions,omitempty"`
|
||||
Size uint64 `json:"size,omitempty"`
|
||||
Date time.Time `json:"date,omitempty"`
|
||||
Date time.Time `json:"date"`
|
||||
UID uint32 `json:"uid,omitempty"`
|
||||
GID uint32 `json:"gid,omitempty"`
|
||||
}
|
||||
@@ -154,7 +154,7 @@ type JSONOutput struct {
|
||||
Path string `json:"path"`
|
||||
ParentTree string `json:"parent_tree,omitempty"`
|
||||
SnapshotID string `json:"snapshot"`
|
||||
Time time.Time `json:"time,omitempty"`
|
||||
Time time.Time `json:"time"`
|
||||
}
|
||||
|
||||
func TestFindPackfile(t *testing.T) {
|
||||
|
||||
@@ -130,9 +130,9 @@ type lsNodeOutput struct {
|
||||
Size *uint64 `json:"size,omitempty"`
|
||||
Mode os.FileMode `json:"mode,omitempty"`
|
||||
Permissions string `json:"permissions,omitempty"`
|
||||
ModTime time.Time `json:"mtime,omitempty"`
|
||||
AccessTime time.Time `json:"atime,omitempty"`
|
||||
ChangeTime time.Time `json:"ctime,omitempty"`
|
||||
ModTime time.Time `json:"mtime"`
|
||||
AccessTime time.Time `json:"atime"`
|
||||
ChangeTime time.Time `json:"ctime"`
|
||||
Inode uint64 `json:"inode,omitempty"`
|
||||
MessageType string `json:"message_type"`
|
||||
StructType string `json:"struct_type"`
|
||||
@@ -290,8 +290,8 @@ type textLsPrinter struct {
|
||||
ListLong bool
|
||||
HumanReadable bool
|
||||
termPrinter interface {
|
||||
P(msg string, args ...interface{})
|
||||
S(msg string, args ...interface{})
|
||||
P(msg string, args ...any)
|
||||
S(msg string, args ...any)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ func TestLsNodeJSON(t *testing.T) {
|
||||
rtest.Equals(t, expect+"\n", buf.String())
|
||||
|
||||
// Sanity check: output must be valid JSON.
|
||||
var v interface{}
|
||||
var v any
|
||||
err = json.NewDecoder(buf).Decode(&v)
|
||||
rtest.OK(t, err)
|
||||
}
|
||||
@@ -121,7 +121,7 @@ func TestLsNcduNode(t *testing.T) {
|
||||
rtest.Equals(t, expect, string(out))
|
||||
|
||||
// Sanity check: output must be valid JSON.
|
||||
var v interface{}
|
||||
var v any
|
||||
err = json.Unmarshal(out, &v)
|
||||
rtest.OK(t, err)
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ func runMount(ctx context.Context, opts MountOptions, gopts global.Options, args
|
||||
}
|
||||
}
|
||||
|
||||
systemFuse.Debug = func(msg interface{}) {
|
||||
systemFuse.Debug = func(msg any) {
|
||||
debug.Log("fuse: %v", msg)
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ func snapshotsDirExists(t testing.TB, dir string) bool {
|
||||
// waitForMount blocks (max mountWait * mountSleep) until the subdir
|
||||
// "snapshots" appears in the dir.
|
||||
func waitForMount(t testing.TB, dir string) {
|
||||
for i := 0; i < mountWait; i++ {
|
||||
for range mountWait {
|
||||
if snapshotsDirExists(t, dir) {
|
||||
t.Log("mounted directory is ready")
|
||||
return
|
||||
@@ -70,7 +70,7 @@ func testRunMount(t testing.TB, gopts global.Options, dir string, wg *sync.WaitG
|
||||
|
||||
func testRunUmount(t testing.TB, dir string) {
|
||||
var err error
|
||||
for i := 0; i < mountWait; i++ {
|
||||
for range mountWait {
|
||||
if err = systemFuse.Unmount(dir); err == nil {
|
||||
t.Logf("directory %v umounted", dir)
|
||||
return
|
||||
|
||||
@@ -243,7 +243,7 @@ func TestRestore(t *testing.T) {
|
||||
|
||||
testRunInit(t, env.gopts)
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
for i := range 10 {
|
||||
p := filepath.Join(env.testdata, fmt.Sprintf("foo/bar/testfile%v", i))
|
||||
rtest.OK(t, os.MkdirAll(filepath.Dir(p), 0755))
|
||||
rtest.OK(t, appendRandomData(p, uint(rand.Intn(2<<21))))
|
||||
|
||||
@@ -43,7 +43,7 @@ func testLsOutputContainsCount(t testing.TB, gopts global.Options, lsOpts LsOpti
|
||||
t.Helper()
|
||||
out := testRunLsWithOpts(t, gopts, lsOpts, lsArgs)
|
||||
count := 0
|
||||
for _, line := range strings.Split(string(out), "\n") {
|
||||
for line := range strings.SplitSeq(string(out), "\n") {
|
||||
if strings.Contains(line, substring) {
|
||||
count++
|
||||
}
|
||||
|
||||
@@ -415,7 +415,7 @@ func statsDebugFileType(ctx context.Context, repo restic.Lister, tpe restic.File
|
||||
|
||||
func statsDebugBlobs(ctx context.Context, repo restic.Repository) ([restic.NumBlobTypes]*sizeHistogram, error) {
|
||||
var hist [restic.NumBlobTypes]*sizeHistogram
|
||||
for i := 0; i < len(hist); i++ {
|
||||
for i := range len(hist) {
|
||||
hist[i] = newSizeHistogram(2 * chunker.MaxSize)
|
||||
}
|
||||
|
||||
@@ -446,10 +446,7 @@ func newSizeHistogram(sizeLimit uint64) *sizeHistogram {
|
||||
growthFactor := uint64(10)
|
||||
|
||||
for lowerBound < sizeLimit {
|
||||
upperBound := lowerBound*growthFactor - 1
|
||||
if upperBound > sizeLimit {
|
||||
upperBound = sizeLimit
|
||||
}
|
||||
upperBound := min(lowerBound*growthFactor-1, sizeLimit)
|
||||
h.buckets = append(h.buckets, sizeClass{lowerBound, upperBound, 0})
|
||||
lowerBound *= growthFactor
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ func TestSizeHistogramNew(t *testing.T) {
|
||||
|
||||
func TestSizeHistogramAdd(t *testing.T) {
|
||||
h := newSizeHistogram(42)
|
||||
for i := uint64(0); i < 45; i++ {
|
||||
for i := range uint64(45) {
|
||||
h.Add(i)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -339,13 +340,7 @@ func removePacksExcept(gopts global.Options, t testing.TB, keep restic.IDSet, re
|
||||
}
|
||||
|
||||
func includes(haystack []string, needle string) bool {
|
||||
for _, s := range haystack {
|
||||
if s == needle {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
return slices.Contains(haystack, needle)
|
||||
}
|
||||
|
||||
func loadSnapshotMap(t testing.TB, gopts global.Options) map[string]struct{} {
|
||||
|
||||
@@ -39,7 +39,7 @@ func init() {
|
||||
pflag.Parse()
|
||||
}
|
||||
|
||||
func die(f string, args ...interface{}) {
|
||||
func die(f string, args ...any) {
|
||||
if !strings.HasSuffix(f, "\n") {
|
||||
f += "\n"
|
||||
}
|
||||
@@ -48,7 +48,7 @@ func die(f string, args ...interface{}) {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
func msg(f string, args ...interface{}) {
|
||||
func msg(f string, args ...any) {
|
||||
if !strings.HasSuffix(f, "\n") {
|
||||
f += "\n"
|
||||
}
|
||||
@@ -56,7 +56,7 @@ func msg(f string, args ...interface{}) {
|
||||
fmt.Printf(f, args...)
|
||||
}
|
||||
|
||||
func verbose(f string, args ...interface{}) {
|
||||
func verbose(f string, args ...any) {
|
||||
if !opts.Verbose {
|
||||
return
|
||||
}
|
||||
@@ -207,10 +207,7 @@ func buildForTarget(sourceDir, outputDir, goos, goarch string) (filename string)
|
||||
func buildTargets(sourceDir, outputDir string, targets map[string][]string) {
|
||||
start := time.Now()
|
||||
// the go compiler is already parallelized, thus reduce the concurrency a bit
|
||||
workers := runtime.GOMAXPROCS(0) / 4
|
||||
if workers < 1 {
|
||||
workers = 1
|
||||
}
|
||||
workers := max(runtime.GOMAXPROCS(0)/4, 1)
|
||||
msg("building with %d workers", workers)
|
||||
|
||||
type Job struct{ GOOS, GOARCH string }
|
||||
@@ -218,7 +215,7 @@ func buildTargets(sourceDir, outputDir string, targets map[string][]string) {
|
||||
var wg errgroup.Group
|
||||
ch := make(chan Job)
|
||||
|
||||
for i := 0; i < workers; i++ {
|
||||
for range workers {
|
||||
wg.Go(func() error {
|
||||
for job := range ch {
|
||||
start := time.Now()
|
||||
|
||||
@@ -43,7 +43,7 @@ func init() {
|
||||
pflag.Parse()
|
||||
}
|
||||
|
||||
func die(f string, args ...interface{}) {
|
||||
func die(f string, args ...any) {
|
||||
if !strings.HasSuffix(f, "\n") {
|
||||
f += "\n"
|
||||
}
|
||||
@@ -52,7 +52,7 @@ func die(f string, args ...interface{}) {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
func msg(f string, args ...interface{}) {
|
||||
func msg(f string, args ...any) {
|
||||
if !strings.HasSuffix(f, "\n") {
|
||||
f += "\n"
|
||||
}
|
||||
@@ -428,11 +428,11 @@ func updateDocker(sourceDir, version string) string {
|
||||
buildCmd := fmt.Sprintf("docker buildx build --builder %s --platform linux/386,linux/amd64,linux/arm,linux/arm64 --pull -f docker/Dockerfile.release %q", builderName, sourceDir)
|
||||
run("sh", "-c", buildCmd+" --no-cache")
|
||||
|
||||
publishCmds := ""
|
||||
var publishCmds strings.Builder
|
||||
for _, tag := range []string{"restic/restic:latest", "restic/restic:" + version} {
|
||||
publishCmds += buildCmd + fmt.Sprintf(" --tag %q --push\n", tag)
|
||||
publishCmds.WriteString(buildCmd + fmt.Sprintf(" --tag %q --push\n", tag))
|
||||
}
|
||||
return publishCmds + "\ndocker buildx rm " + builderName
|
||||
return publishCmds.String() + "\ndocker buildx rm " + builderName
|
||||
}
|
||||
|
||||
func tempdir(prefix string) string {
|
||||
|
||||
@@ -132,8 +132,7 @@ func TestArchiverSaveFile(t *testing.T) {
|
||||
|
||||
for _, testfile := range tests {
|
||||
t.Run("", func(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
ctx := t.Context()
|
||||
|
||||
tempdir, repo := prepareTempdirRepoSrc(t, TestDir{"file": testfile})
|
||||
node, stats := saveFile(t, repo, filepath.Join(tempdir, "file"), fs.Track{FS: fs.NewLocal()})
|
||||
@@ -165,8 +164,7 @@ func TestArchiverSaveFileReaderFS(t *testing.T) {
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run("", func(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
ctx := t.Context()
|
||||
|
||||
repo := repository.TestRepository(t)
|
||||
|
||||
@@ -206,8 +204,7 @@ func TestArchiverSave(t *testing.T) {
|
||||
|
||||
for _, testfile := range tests {
|
||||
t.Run("", func(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
ctx := t.Context()
|
||||
|
||||
tempdir, repo := prepareTempdirRepoSrc(t, TestDir{"file": testfile})
|
||||
|
||||
@@ -276,8 +273,7 @@ func TestArchiverSaveReaderFS(t *testing.T) {
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run("", func(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
ctx := t.Context()
|
||||
|
||||
repo := repository.TestRepository(t)
|
||||
|
||||
@@ -477,7 +473,7 @@ func TestArchiverSaveFileIncremental(t *testing.T) {
|
||||
data := rtest.Random(23, 512*1024+887898)
|
||||
testfile := filepath.Join(tempdir, "testfile")
|
||||
|
||||
for i := 0; i < 3; i++ {
|
||||
for i := range 3 {
|
||||
appendToFile(t, testfile, data)
|
||||
node, _ := saveFile(t, repo, testfile, fs.Track{FS: fs.NewLocal()})
|
||||
|
||||
@@ -984,7 +980,7 @@ func TestArchiverSaveDirIncremental(t *testing.T) {
|
||||
|
||||
// save the empty directory several times in a row, then have a look if the
|
||||
// archiver did save the same tree several times
|
||||
for i := 0; i < 5; i++ {
|
||||
for i := range 5 {
|
||||
testFS := fs.Track{FS: fs.NewLocal()}
|
||||
arch := New(repo, testFS, Options{})
|
||||
arch.summary = &Summary{}
|
||||
@@ -1461,8 +1457,7 @@ func TestArchiverSnapshot(t *testing.T) {
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
ctx := t.Context()
|
||||
|
||||
tempdir, repo := prepareTempdirRepoSrc(t, test.src)
|
||||
|
||||
@@ -1682,8 +1677,7 @@ func TestArchiverSnapshotSelect(t *testing.T) {
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
ctx := t.Context()
|
||||
|
||||
tempdir, repo := prepareTempdirRepoSrc(t, test.src)
|
||||
|
||||
@@ -1790,8 +1784,7 @@ func TestArchiverExplicitBackupTarget(t *testing.T) {
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
ctx := t.Context()
|
||||
|
||||
tempdir, repo := prepareTempdirRepoSrc(t, test.src)
|
||||
|
||||
@@ -1956,8 +1949,7 @@ func TestArchiverParent(t *testing.T) {
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run("", func(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
ctx := t.Context()
|
||||
|
||||
tempdir, repo := prepareTempdirRepoSrc(t, test.src)
|
||||
|
||||
@@ -1982,7 +1974,7 @@ func TestArchiverParent(t *testing.T) {
|
||||
t.Logf("testfs: %v", testFS)
|
||||
|
||||
// check that all files have been read exactly once
|
||||
TestWalkFiles(t, ".", test.src, func(filename string, item interface{}) error {
|
||||
TestWalkFiles(t, ".", test.src, func(filename string, item any) error {
|
||||
file, ok := item.(TestFile)
|
||||
if !ok {
|
||||
return nil
|
||||
@@ -2144,8 +2136,7 @@ func TestArchiverErrorReporting(t *testing.T) {
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
ctx := t.Context()
|
||||
|
||||
tempdir, repo := prepareTempdirRepoSrc(t, test.src)
|
||||
|
||||
@@ -2370,8 +2361,7 @@ func TestArchiverAbortEarlyOnError(t *testing.T) {
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run("", func(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
ctx := t.Context()
|
||||
|
||||
tempdir, repo := prepareTempdirRepoSrc(t, test.src)
|
||||
|
||||
@@ -2618,8 +2608,7 @@ func TestRacyFileTypeSwap(t *testing.T) {
|
||||
resetFIOnRead: true,
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
ctx := t.Context()
|
||||
|
||||
_ = repo.WithBlobUploader(ctx, func(ctx context.Context, uploader restic.BlobSaverWithAsync) error {
|
||||
wg, ctx := errgroup.WithContext(ctx)
|
||||
@@ -2717,8 +2706,7 @@ func TestIrregularFile(t *testing.T) {
|
||||
overrideErr: fmt.Errorf(`unsupported file type "irregular"`),
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
ctx := t.Context()
|
||||
|
||||
arch := New(repo, fs.Track{FS: override}, Options{})
|
||||
_, excluded, err := arch.save(ctx, "/", tempfile, nil, false)
|
||||
@@ -2764,8 +2752,7 @@ func TestDisappearedFile(t *testing.T) {
|
||||
back := rtest.Chdir(t, tempdir)
|
||||
defer back()
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
ctx := t.Context()
|
||||
|
||||
// depending on the underlying FS implementation a missing file may be detected by OpenFile or
|
||||
// the subsequent file.Stat() call. Thus test both cases.
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
func TestBufferPoolReuse(t *testing.T) {
|
||||
success := false
|
||||
// retries to avoid flakiness. The test can fail depending on the GC.
|
||||
for i := 0; i < 100; i++ {
|
||||
for range 100 {
|
||||
// Test that buffers are actually reused from the pool
|
||||
pool := newBufferPool(1024)
|
||||
|
||||
@@ -33,7 +33,7 @@ func TestBufferPoolReuse(t *testing.T) {
|
||||
func TestBufferPoolLargeBuffers(t *testing.T) {
|
||||
success := false
|
||||
// retries to avoid flakiness. The test can fail depending on the GC.
|
||||
for i := 0; i < 100; i++ {
|
||||
for range 100 {
|
||||
// Test that buffers larger than defaultSize are not returned to pool
|
||||
pool := newBufferPool(1024)
|
||||
buf := pool.Get()
|
||||
|
||||
@@ -88,7 +88,7 @@ func (rc *rejectionCache) Store(dir string, rejected bool) {
|
||||
// non-nil if the filename component of excludeFileSpec is empty. If rc is
|
||||
// non-nil, it is going to be used in the RejectByNameFunc to expedite the evaluation
|
||||
// of a directory based on previous visits.
|
||||
func RejectIfPresent(excludeFileSpec string, warnf func(msg string, args ...interface{})) (RejectFunc, error) {
|
||||
func RejectIfPresent(excludeFileSpec string, warnf func(msg string, args ...any)) (RejectFunc, error) {
|
||||
if excludeFileSpec == "" {
|
||||
return nil, errors.New("name for exclusion tagfile is empty")
|
||||
}
|
||||
@@ -115,7 +115,7 @@ func RejectIfPresent(excludeFileSpec string, warnf func(msg string, args ...inte
|
||||
// tagfile which bears the name specified in tagFilename and starts with
|
||||
// header. If rc is non-nil, it is used to expedite the evaluation of a
|
||||
// directory based on previous visits.
|
||||
func isExcludedByFile(filename, tagFilename, header string, rc *rejectionCache, fs fs.FS, warnf func(msg string, args ...interface{})) bool {
|
||||
func isExcludedByFile(filename, tagFilename, header string, rc *rejectionCache, fs fs.FS, warnf func(msg string, args ...any)) bool {
|
||||
if tagFilename == "" {
|
||||
return false
|
||||
}
|
||||
@@ -136,7 +136,7 @@ func isExcludedByFile(filename, tagFilename, header string, rc *rejectionCache,
|
||||
return rejected
|
||||
}
|
||||
|
||||
func isDirExcludedByFile(dir, tagFilename, header string, fsInst fs.FS, warnf func(msg string, args ...interface{})) bool {
|
||||
func isDirExcludedByFile(dir, tagFilename, header string, fsInst fs.FS, warnf func(msg string, args ...any)) bool {
|
||||
tf := fsInst.Join(dir, tagFilename)
|
||||
_, err := fsInst.Lstat(tf)
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
@@ -318,7 +318,7 @@ func RejectBySize(maxSize int64) (RejectFunc, error) {
|
||||
}
|
||||
|
||||
// RejectCloudFiles returns a func which rejects files which are online-only cloud files
|
||||
func RejectCloudFiles(warnf func(msg string, args ...interface{})) (RejectFunc, error) {
|
||||
func RejectCloudFiles(warnf func(msg string, args ...any)) (RejectFunc, error) {
|
||||
return func(item string, fi *fs.ExtendedFileInfo, _ fs.FS) bool {
|
||||
recall, err := fi.RecallOnDataAccess()
|
||||
if err != nil {
|
||||
|
||||
@@ -49,7 +49,7 @@ func TestIsExcludedByFile(t *testing.T) {
|
||||
if tc.content == "" {
|
||||
h = ""
|
||||
}
|
||||
if got := isExcludedByFile(foo, tagFilename, h, newRejectionCache(), fs.NewLocal(), func(msg string, args ...interface{}) { t.Logf(msg, args...) }); tc.want != got {
|
||||
if got := isExcludedByFile(foo, tagFilename, h, newRejectionCache(), fs.NewLocal(), func(msg string, args ...any) { t.Logf(msg, args...) }); tc.want != got {
|
||||
t.Fatalf("expected %v, got %v", tc.want, got)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -45,7 +45,7 @@ func newFileSaver(ctx context.Context, wg *errgroup.Group, uploader restic.BlobS
|
||||
CompleteBlob: func(uint64) {},
|
||||
}
|
||||
|
||||
for i := uint(0); i < fileWorkers; i++ {
|
||||
for range fileWorkers {
|
||||
wg.Go(func() error {
|
||||
s.worker(ctx, ch)
|
||||
return nil
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
func createTestFiles(t testing.TB, num int) (files []string) {
|
||||
tempdir := test.TempDir(t)
|
||||
|
||||
for i := 0; i < num; i++ {
|
||||
for i := range num {
|
||||
filename := fmt.Sprintf("testfile-%d", i)
|
||||
err := os.WriteFile(filepath.Join(tempdir, filename), []byte(filename), 0600)
|
||||
if err != nil {
|
||||
@@ -46,8 +46,7 @@ func startFileSaver(ctx context.Context, t testing.TB, _ fs.FS) (*fileSaver, *mo
|
||||
}
|
||||
|
||||
func TestFileSaver(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
ctx := t.Context()
|
||||
|
||||
startFn := func() {}
|
||||
completeReadingFn := func() {}
|
||||
|
||||
@@ -78,8 +78,7 @@ func TestScanner(t *testing.T) {
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
ctx := t.Context()
|
||||
|
||||
tempdir := rtest.TempDir(t)
|
||||
TestCreateFiles(t, tempdir, test.src)
|
||||
@@ -213,8 +212,7 @@ func TestScannerError(t *testing.T) {
|
||||
t.Skipf("skip on windows")
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
ctx := t.Context()
|
||||
|
||||
tempdir := rtest.TempDir(t)
|
||||
TestCreateFiles(t, tempdir, test.src)
|
||||
|
||||
@@ -41,7 +41,7 @@ func TestSnapshot(t testing.TB, repo restic.Repository, path string, parent *res
|
||||
}
|
||||
|
||||
// TestDir describes a directory structure to create for a test.
|
||||
type TestDir map[string]interface{}
|
||||
type TestDir map[string]any
|
||||
|
||||
func (d TestDir) String() string {
|
||||
return "<Dir>"
|
||||
@@ -119,7 +119,7 @@ func TestCreateFiles(t testing.TB, target string, dir TestDir) {
|
||||
|
||||
// TestWalkFunc is used by TestWalkFiles to traverse the dir. When an error is
|
||||
// returned, traversal stops and the surrounding test is marked as failed.
|
||||
type TestWalkFunc func(path string, item interface{}) error
|
||||
type TestWalkFunc func(path string, item any) error
|
||||
|
||||
// TestWalkFiles runs fn for each file/directory in dir, the filename will be
|
||||
// constructed with target as the prefix. Symlinks on Windows are ignored.
|
||||
@@ -158,7 +158,7 @@ func TestEnsureFiles(t testing.TB, target string, dir TestDir) {
|
||||
pathsChecked := make(map[string]struct{})
|
||||
|
||||
// first, test that all items are there
|
||||
TestWalkFiles(t, target, dir, func(path string, item interface{}) error {
|
||||
TestWalkFiles(t, target, dir, func(path string, item any) error {
|
||||
fi, err := os.Lstat(path)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package archiver
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -28,30 +27,30 @@ func (t *MockT) Fail() {
|
||||
}
|
||||
|
||||
// Fatal is equivalent to Log followed by FailNow.
|
||||
func (t *MockT) Fatal(args ...interface{}) {
|
||||
func (t *MockT) Fatal(args ...any) {
|
||||
t.T.Logf("MockT Fatal called with %v", args)
|
||||
t.HasFailed = true
|
||||
}
|
||||
|
||||
// Fatalf is equivalent to Logf followed by FailNow.
|
||||
func (t *MockT) Fatalf(msg string, args ...interface{}) {
|
||||
func (t *MockT) Fatalf(msg string, args ...any) {
|
||||
t.T.Logf("MockT Fatal called: "+msg, args...)
|
||||
t.HasFailed = true
|
||||
}
|
||||
|
||||
// Error is equivalent to Log followed by Fail.
|
||||
func (t *MockT) Error(args ...interface{}) {
|
||||
func (t *MockT) Error(args ...any) {
|
||||
t.T.Logf("MockT Error called with %v", args)
|
||||
t.HasFailed = true
|
||||
}
|
||||
|
||||
// Errorf is equivalent to Logf followed by Fail.
|
||||
func (t *MockT) Errorf(msg string, args ...interface{}) {
|
||||
func (t *MockT) Errorf(msg string, args ...any) {
|
||||
t.T.Logf("MockT Error called: "+msg, args...)
|
||||
t.HasFailed = true
|
||||
}
|
||||
|
||||
func createFilesAt(t testing.TB, targetdir string, files map[string]interface{}) {
|
||||
func createFilesAt(t testing.TB, targetdir string, files map[string]any) {
|
||||
for name, item := range files {
|
||||
target := filepath.Join(targetdir, filepath.FromSlash(name))
|
||||
err := os.MkdirAll(filepath.Dir(target), 0700)
|
||||
@@ -77,7 +76,7 @@ func createFilesAt(t testing.TB, targetdir string, files map[string]interface{})
|
||||
func TestTestCreateFiles(t *testing.T) {
|
||||
var tests = []struct {
|
||||
dir TestDir
|
||||
files map[string]interface{}
|
||||
files map[string]any
|
||||
}{
|
||||
{
|
||||
dir: TestDir{
|
||||
@@ -91,7 +90,7 @@ func TestTestCreateFiles(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
files: map[string]interface{}{
|
||||
files: map[string]any{
|
||||
"foo": TestFile{Content: "foo"},
|
||||
"subdir": TestDir{},
|
||||
"subdir/subfile": TestFile{Content: "bar"},
|
||||
@@ -196,7 +195,7 @@ func TestTestWalkFiles(t *testing.T) {
|
||||
got := make(map[string]string)
|
||||
|
||||
TestCreateFiles(t, tempdir, test.dir)
|
||||
TestWalkFiles(t, tempdir, test.dir, func(path string, item interface{}) error {
|
||||
TestWalkFiles(t, tempdir, test.dir, func(path string, item any) error {
|
||||
p, err := filepath.Rel(tempdir, path)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -216,11 +215,11 @@ func TestTestWalkFiles(t *testing.T) {
|
||||
func TestTestEnsureFiles(t *testing.T) {
|
||||
var tests = []struct {
|
||||
expectFailure bool
|
||||
files map[string]interface{}
|
||||
files map[string]any
|
||||
want TestDir
|
||||
}{
|
||||
{
|
||||
files: map[string]interface{}{
|
||||
files: map[string]any{
|
||||
"foo": TestFile{Content: "foo"},
|
||||
"subdir/subfile": TestFile{Content: "bar"},
|
||||
"x/y/link": TestSymlink{Target: filepath.Clean("../../foo")},
|
||||
@@ -239,7 +238,7 @@ func TestTestEnsureFiles(t *testing.T) {
|
||||
},
|
||||
{
|
||||
expectFailure: true,
|
||||
files: map[string]interface{}{
|
||||
files: map[string]any{
|
||||
"foo": TestFile{Content: "foo"},
|
||||
},
|
||||
want: TestDir{
|
||||
@@ -251,7 +250,7 @@ func TestTestEnsureFiles(t *testing.T) {
|
||||
},
|
||||
{
|
||||
expectFailure: true,
|
||||
files: map[string]interface{}{
|
||||
files: map[string]any{
|
||||
"foo": TestFile{Content: "foo"},
|
||||
"subdir/subfile": TestFile{Content: "bar"},
|
||||
},
|
||||
@@ -261,7 +260,7 @@ func TestTestEnsureFiles(t *testing.T) {
|
||||
},
|
||||
{
|
||||
expectFailure: true,
|
||||
files: map[string]interface{}{
|
||||
files: map[string]any{
|
||||
"foo": TestFile{Content: "xxx"},
|
||||
},
|
||||
want: TestDir{
|
||||
@@ -270,7 +269,7 @@ func TestTestEnsureFiles(t *testing.T) {
|
||||
},
|
||||
{
|
||||
expectFailure: true,
|
||||
files: map[string]interface{}{
|
||||
files: map[string]any{
|
||||
"foo": TestSymlink{Target: "/xxx"},
|
||||
},
|
||||
want: TestDir{
|
||||
@@ -279,7 +278,7 @@ func TestTestEnsureFiles(t *testing.T) {
|
||||
},
|
||||
{
|
||||
expectFailure: true,
|
||||
files: map[string]interface{}{
|
||||
files: map[string]any{
|
||||
"foo": TestFile{Content: "foo"},
|
||||
},
|
||||
want: TestDir{
|
||||
@@ -288,7 +287,7 @@ func TestTestEnsureFiles(t *testing.T) {
|
||||
},
|
||||
{
|
||||
expectFailure: true,
|
||||
files: map[string]interface{}{
|
||||
files: map[string]any{
|
||||
"foo": TestSymlink{Target: "xxx"},
|
||||
},
|
||||
want: TestDir{
|
||||
@@ -297,7 +296,7 @@ func TestTestEnsureFiles(t *testing.T) {
|
||||
},
|
||||
{
|
||||
expectFailure: true,
|
||||
files: map[string]interface{}{
|
||||
files: map[string]any{
|
||||
"foo": TestDir{
|
||||
"foo": TestFile{Content: "foo"},
|
||||
},
|
||||
@@ -308,7 +307,7 @@ func TestTestEnsureFiles(t *testing.T) {
|
||||
},
|
||||
{
|
||||
expectFailure: true,
|
||||
files: map[string]interface{}{
|
||||
files: map[string]any{
|
||||
"foo": TestFile{Content: "foo"},
|
||||
},
|
||||
want: TestDir{
|
||||
@@ -341,11 +340,11 @@ func TestTestEnsureFiles(t *testing.T) {
|
||||
func TestTestEnsureSnapshot(t *testing.T) {
|
||||
var tests = []struct {
|
||||
expectFailure bool
|
||||
files map[string]interface{}
|
||||
files map[string]any
|
||||
want TestDir
|
||||
}{
|
||||
{
|
||||
files: map[string]interface{}{
|
||||
files: map[string]any{
|
||||
"foo": TestFile{Content: "foo"},
|
||||
filepath.FromSlash("subdir/subfile"): TestFile{Content: "bar"},
|
||||
filepath.FromSlash("x/y/link"): TestSymlink{Target: filepath.FromSlash("../../foo")},
|
||||
@@ -366,7 +365,7 @@ func TestTestEnsureSnapshot(t *testing.T) {
|
||||
},
|
||||
{
|
||||
expectFailure: true,
|
||||
files: map[string]interface{}{
|
||||
files: map[string]any{
|
||||
"foo": TestFile{Content: "foo"},
|
||||
},
|
||||
want: TestDir{
|
||||
@@ -377,7 +376,7 @@ func TestTestEnsureSnapshot(t *testing.T) {
|
||||
},
|
||||
{
|
||||
expectFailure: true,
|
||||
files: map[string]interface{}{
|
||||
files: map[string]any{
|
||||
"foo": TestFile{Content: "foo"},
|
||||
"bar": TestFile{Content: "bar"},
|
||||
},
|
||||
@@ -389,7 +388,7 @@ func TestTestEnsureSnapshot(t *testing.T) {
|
||||
},
|
||||
{
|
||||
expectFailure: true,
|
||||
files: map[string]interface{}{
|
||||
files: map[string]any{
|
||||
"foo": TestFile{Content: "foo"},
|
||||
},
|
||||
want: TestDir{
|
||||
@@ -401,7 +400,7 @@ func TestTestEnsureSnapshot(t *testing.T) {
|
||||
},
|
||||
{
|
||||
expectFailure: true,
|
||||
files: map[string]interface{}{
|
||||
files: map[string]any{
|
||||
"foo": TestFile{Content: "foo"},
|
||||
},
|
||||
want: TestDir{
|
||||
@@ -414,7 +413,7 @@ func TestTestEnsureSnapshot(t *testing.T) {
|
||||
},
|
||||
{
|
||||
expectFailure: true,
|
||||
files: map[string]interface{}{
|
||||
files: map[string]any{
|
||||
"foo": TestSymlink{Target: filepath.FromSlash("x/y/z")},
|
||||
},
|
||||
want: TestDir{
|
||||
@@ -425,7 +424,7 @@ func TestTestEnsureSnapshot(t *testing.T) {
|
||||
},
|
||||
{
|
||||
expectFailure: true,
|
||||
files: map[string]interface{}{
|
||||
files: map[string]any{
|
||||
"foo": TestSymlink{Target: filepath.FromSlash("x/y/z")},
|
||||
},
|
||||
want: TestDir{
|
||||
@@ -436,7 +435,7 @@ func TestTestEnsureSnapshot(t *testing.T) {
|
||||
},
|
||||
{
|
||||
expectFailure: true,
|
||||
files: map[string]interface{}{
|
||||
files: map[string]any{
|
||||
"foo": TestFile{Content: "foo"},
|
||||
},
|
||||
want: TestDir{
|
||||
@@ -449,8 +448,7 @@ func TestTestEnsureSnapshot(t *testing.T) {
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run("", func(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
ctx := t.Context()
|
||||
|
||||
tempdir := rtest.TempDir(t)
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ func newTreeSaver(ctx context.Context, wg *errgroup.Group, treeWorkers uint, upl
|
||||
errFn: errFn,
|
||||
}
|
||||
|
||||
for i := uint(0); i < treeWorkers; i++ {
|
||||
for range treeWorkers {
|
||||
wg.Go(func() error {
|
||||
return s.worker(ctx, ch)
|
||||
})
|
||||
|
||||
@@ -54,7 +54,7 @@ func TestTreeSaver(t *testing.T) {
|
||||
|
||||
var results []futureNode
|
||||
|
||||
for i := 0; i < 20; i++ {
|
||||
for i := range 20 {
|
||||
node := &data.Node{
|
||||
Name: fmt.Sprintf("file-%d", i),
|
||||
}
|
||||
|
||||
@@ -158,13 +158,13 @@ func supportedAccessTiers() []blob.AccessTier {
|
||||
}
|
||||
|
||||
// Open opens the Azure backend at specified container.
|
||||
func Open(_ context.Context, cfg Config, rt http.RoundTripper, _ func(string, ...interface{})) (*Backend, error) {
|
||||
func Open(_ context.Context, cfg Config, rt http.RoundTripper, _ func(string, ...any)) (*Backend, error) {
|
||||
return open(cfg, rt)
|
||||
}
|
||||
|
||||
// Create opens the Azure backend at specified container and creates the container if
|
||||
// it does not exist yet.
|
||||
func Create(ctx context.Context, cfg Config, rt http.RoundTripper, _ func(string, ...interface{})) (*Backend, error) {
|
||||
func Create(ctx context.Context, cfg Config, rt http.RoundTripper, _ func(string, ...any)) (*Backend, error) {
|
||||
be, err := open(cfg, rt)
|
||||
|
||||
if err != nil {
|
||||
|
||||
@@ -2,7 +2,6 @@ package azure_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
@@ -100,8 +99,7 @@ func TestBackendAzureAccountToken(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.TODO())
|
||||
defer cancel()
|
||||
ctx := t.Context()
|
||||
|
||||
cfg, err := azure.ParseConfig(os.Getenv("RESTIC_TEST_AZURE_REPOSITORY"))
|
||||
if err != nil {
|
||||
@@ -143,8 +141,7 @@ func TestBackendAzureContainerToken(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.TODO())
|
||||
defer cancel()
|
||||
ctx := t.Context()
|
||||
|
||||
cfg, err := azure.ParseConfig(os.Getenv("RESTIC_TEST_AZURE_REPOSITORY"))
|
||||
if err != nil {
|
||||
@@ -171,8 +168,7 @@ func TestUploadLargeFile(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.TODO())
|
||||
defer cancel()
|
||||
ctx := t.Context()
|
||||
|
||||
if os.Getenv("RESTIC_TEST_AZURE_REPOSITORY") == "" {
|
||||
t.Skipf("environment variables not available")
|
||||
|
||||
@@ -87,7 +87,7 @@ func newClient(ctx context.Context, cfg Config, rt http.RoundTripper) (*b2.Clien
|
||||
}
|
||||
|
||||
// Open opens a connection to the B2 service.
|
||||
func Open(ctx context.Context, cfg Config, rt http.RoundTripper, _ func(string, ...interface{})) (backend.Backend, error) {
|
||||
func Open(ctx context.Context, cfg Config, rt http.RoundTripper, _ func(string, ...any)) (backend.Backend, error) {
|
||||
debug.Log("cfg %#v", cfg)
|
||||
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
@@ -118,7 +118,7 @@ func Open(ctx context.Context, cfg Config, rt http.RoundTripper, _ func(string,
|
||||
|
||||
// Create opens a connection to the B2 service. If the bucket does not exist yet,
|
||||
// it is created.
|
||||
func Create(ctx context.Context, cfg Config, rt http.RoundTripper, _ func(string, ...interface{})) (backend.Backend, error) {
|
||||
func Create(ctx context.Context, cfg Config, rt http.RoundTripper, _ func(string, ...any)) (backend.Backend, error) {
|
||||
debug.Log("cfg %#v", cfg)
|
||||
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
@@ -258,7 +258,7 @@ func (be *b2Backend) Stat(ctx context.Context, h backend.Handle) (bi backend.Fil
|
||||
// Remove removes the blob with the given name and type.
|
||||
func (be *b2Backend) Remove(ctx context.Context, h backend.Handle) error {
|
||||
// the retry backend will also repeat the remove method up to 10 times
|
||||
for i := 0; i < 3; i++ {
|
||||
for range 3 {
|
||||
obj := be.bucket.Object(be.Filename(h))
|
||||
|
||||
var err error
|
||||
|
||||
Vendored
+2
-2
@@ -19,13 +19,13 @@ type cacheBackend struct {
|
||||
// is finished.
|
||||
inProgressMutex sync.Mutex
|
||||
inProgress map[backend.Handle]chan struct{}
|
||||
errorLog func(string, ...interface{})
|
||||
errorLog func(string, ...any)
|
||||
}
|
||||
|
||||
// ensure Backend implements backend.Backend
|
||||
var _ backend.Backend = &cacheBackend{}
|
||||
|
||||
func newBackend(be backend.Backend, c *Cache, errorLog func(string, ...interface{})) *cacheBackend {
|
||||
func newBackend(be backend.Backend, c *Cache, errorLog func(string, ...any)) *cacheBackend {
|
||||
return &cacheBackend{
|
||||
Backend: be,
|
||||
Cache: c,
|
||||
|
||||
+1
-1
@@ -238,7 +238,7 @@ func TestErrorBackend(t *testing.T) {
|
||||
|
||||
wrappedBE := c.Wrap(errBackend, t.Logf)
|
||||
var wg sync.WaitGroup
|
||||
for i := 0; i < 5; i++ {
|
||||
for range 5 {
|
||||
wg.Add(1)
|
||||
go loadTest(&wg, wrappedBE)
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -125,7 +125,7 @@ func New(id string, basedir string) (c *Cache, err error) {
|
||||
}
|
||||
|
||||
if v < cacheVersion {
|
||||
err = os.WriteFile(filepath.Join(cachedir, "version"), []byte(fmt.Sprintf("%d", cacheVersion)), fileMode)
|
||||
err = os.WriteFile(filepath.Join(cachedir, "version"), fmt.Appendf(nil, "%d", cacheVersion), fileMode)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
@@ -236,7 +236,7 @@ func IsOld(t time.Time, maxAge time.Duration) bool {
|
||||
}
|
||||
|
||||
// Wrap returns a backend with a cache.
|
||||
func (c *Cache) Wrap(be backend.Backend, errorLog func(string, ...interface{})) backend.Backend {
|
||||
func (c *Cache) Wrap(be backend.Backend, errorLog func(string, ...any)) backend.Backend {
|
||||
return newBackend(be, c, errorLog)
|
||||
}
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -24,7 +24,7 @@ func TestNew(t *testing.T) {
|
||||
stepEnd
|
||||
)
|
||||
|
||||
for step := stepCreate; step < stepEnd; step++ {
|
||||
for step := range stepEnd {
|
||||
switch step {
|
||||
case stepRmTag:
|
||||
rtest.OK(t, os.Remove(tagFile))
|
||||
|
||||
Vendored
+1
-1
@@ -243,7 +243,7 @@ func TestFileSaveConcurrent(t *testing.T) {
|
||||
Name: id.String(),
|
||||
}
|
||||
|
||||
for i := 0; i < nproc/2; i++ {
|
||||
for range nproc / 2 {
|
||||
g.Go(func() error { return c.save(h, bytes.NewReader(data)) })
|
||||
|
||||
// Can't use load because only the main goroutine may call t.Fatal.
|
||||
|
||||
@@ -114,7 +114,7 @@ func open(cfg Config, rt http.RoundTripper) (*gs, error) {
|
||||
}
|
||||
|
||||
// Open opens the gs backend at the specified bucket.
|
||||
func Open(_ context.Context, cfg Config, rt http.RoundTripper, _ func(string, ...interface{})) (backend.Backend, error) {
|
||||
func Open(_ context.Context, cfg Config, rt http.RoundTripper, _ func(string, ...any)) (backend.Backend, error) {
|
||||
return open(cfg, rt)
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ func Open(_ context.Context, cfg Config, rt http.RoundTripper, _ func(string, ..
|
||||
//
|
||||
// The service account must have the "storage.buckets.create" permission to
|
||||
// create a bucket the does not yet exist.
|
||||
func Create(ctx context.Context, cfg Config, rt http.RoundTripper, _ func(string, ...interface{})) (backend.Backend, error) {
|
||||
func Create(ctx context.Context, cfg Config, rt http.RoundTripper, _ func(string, ...any)) (backend.Backend, error) {
|
||||
be, err := open(cfg, rt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -72,7 +72,7 @@ func (l *DefaultLayout) Paths() (dirs []string) {
|
||||
|
||||
if !disablePackSubdirs {
|
||||
// also add subdirs
|
||||
for i := 0; i < 256; i++ {
|
||||
for i := range 256 {
|
||||
subdir := hex.EncodeToString([]byte{byte(i)})
|
||||
dirs = append(dirs, l.join(l.path, defaultLayoutPaths[backend.PackFile], subdir))
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ func TestDefaultLayout(t *testing.T) {
|
||||
filepath.Join(tempdir, "keys"),
|
||||
}
|
||||
|
||||
for i := 0; i < 256; i++ {
|
||||
for i := range 256 {
|
||||
want = append(want, filepath.Join(tempdir, "data", fmt.Sprintf("%02x", i)))
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"github.com/restic/restic/internal/backend"
|
||||
)
|
||||
|
||||
func WrapBackendConstructor[B backend.Backend, C any](constructor func(ctx context.Context, cfg C, errorLog func(string, ...interface{})) (B, error)) func(ctx context.Context, cfg C, lim Limiter, errorLog func(string, ...interface{})) (backend.Backend, error) {
|
||||
return func(ctx context.Context, cfg C, lim Limiter, errorLog func(string, ...interface{})) (backend.Backend, error) {
|
||||
func WrapBackendConstructor[B backend.Backend, C any](constructor func(ctx context.Context, cfg C, errorLog func(string, ...any)) (B, error)) func(ctx context.Context, cfg C, lim Limiter, errorLog func(string, ...any)) (backend.Backend, error) {
|
||||
return func(ctx context.Context, cfg C, lim Limiter, errorLog func(string, ...any)) (backend.Backend, error) {
|
||||
var be backend.Backend
|
||||
be, err := constructor(ctx, cfg, errorLog)
|
||||
if err != nil {
|
||||
|
||||
@@ -52,14 +52,14 @@ func open(cfg Config) (*Local, error) {
|
||||
}
|
||||
|
||||
// Open opens the local backend as specified by config.
|
||||
func Open(_ context.Context, cfg Config, _ func(string, ...interface{})) (*Local, error) {
|
||||
func Open(_ context.Context, cfg Config, _ func(string, ...any)) (*Local, error) {
|
||||
debug.Log("open local backend at %v", cfg.Path)
|
||||
return open(cfg)
|
||||
}
|
||||
|
||||
// Create creates all the necessary files and directories for a new local
|
||||
// backend at dir. Afterwards a new config blob should be created.
|
||||
func Create(_ context.Context, cfg Config, _ func(string, ...interface{})) (*Local, error) {
|
||||
func Create(_ context.Context, cfg Config, _ func(string, ...any)) (*Local, error) {
|
||||
debug.Log("create local backend at %v", cfg.Path)
|
||||
|
||||
be, err := open(cfg)
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
// access and (possibly) credentials needed for access.
|
||||
type Location struct {
|
||||
Scheme string
|
||||
Config interface{}
|
||||
Config any
|
||||
}
|
||||
|
||||
// NoPassword returns the repository location unchanged (there's no sensitive information there)
|
||||
|
||||
@@ -31,25 +31,25 @@ func (r *Registry) Lookup(scheme string) Factory {
|
||||
|
||||
type Factory interface {
|
||||
Scheme() string
|
||||
ParseConfig(s string) (interface{}, error)
|
||||
ParseConfig(s string) (any, error)
|
||||
StripPassword(s string) string
|
||||
Create(ctx context.Context, cfg interface{}, rt http.RoundTripper, lim limiter.Limiter, errorLog func(string, ...interface{})) (backend.Backend, error)
|
||||
Open(ctx context.Context, cfg interface{}, rt http.RoundTripper, lim limiter.Limiter, errorLog func(string, ...interface{})) (backend.Backend, error)
|
||||
Create(ctx context.Context, cfg any, rt http.RoundTripper, lim limiter.Limiter, errorLog func(string, ...any)) (backend.Backend, error)
|
||||
Open(ctx context.Context, cfg any, rt http.RoundTripper, lim limiter.Limiter, errorLog func(string, ...any)) (backend.Backend, error)
|
||||
}
|
||||
|
||||
type genericBackendFactory[C any, T backend.Backend] struct {
|
||||
scheme string
|
||||
parseConfigFn func(s string) (*C, error)
|
||||
stripPasswordFn func(s string) string
|
||||
createFn func(ctx context.Context, cfg C, rt http.RoundTripper, lim limiter.Limiter, errorLog func(string, ...interface{})) (T, error)
|
||||
openFn func(ctx context.Context, cfg C, rt http.RoundTripper, lim limiter.Limiter, errorLog func(string, ...interface{})) (T, error)
|
||||
createFn func(ctx context.Context, cfg C, rt http.RoundTripper, lim limiter.Limiter, errorLog func(string, ...any)) (T, error)
|
||||
openFn func(ctx context.Context, cfg C, rt http.RoundTripper, lim limiter.Limiter, errorLog func(string, ...any)) (T, error)
|
||||
}
|
||||
|
||||
func (f *genericBackendFactory[C, T]) Scheme() string {
|
||||
return f.scheme
|
||||
}
|
||||
|
||||
func (f *genericBackendFactory[C, T]) ParseConfig(s string) (interface{}, error) {
|
||||
func (f *genericBackendFactory[C, T]) ParseConfig(s string) (any, error) {
|
||||
return f.parseConfigFn(s)
|
||||
}
|
||||
func (f *genericBackendFactory[C, T]) StripPassword(s string) string {
|
||||
@@ -58,10 +58,10 @@ func (f *genericBackendFactory[C, T]) StripPassword(s string) string {
|
||||
}
|
||||
return s
|
||||
}
|
||||
func (f *genericBackendFactory[C, T]) Create(ctx context.Context, cfg interface{}, rt http.RoundTripper, lim limiter.Limiter, errorLog func(string, ...interface{})) (backend.Backend, error) {
|
||||
func (f *genericBackendFactory[C, T]) Create(ctx context.Context, cfg any, rt http.RoundTripper, lim limiter.Limiter, errorLog func(string, ...any)) (backend.Backend, error) {
|
||||
return f.createFn(ctx, *cfg.(*C), rt, lim, errorLog)
|
||||
}
|
||||
func (f *genericBackendFactory[C, T]) Open(ctx context.Context, cfg interface{}, rt http.RoundTripper, lim limiter.Limiter, errorLog func(string, ...interface{})) (backend.Backend, error) {
|
||||
func (f *genericBackendFactory[C, T]) Open(ctx context.Context, cfg any, rt http.RoundTripper, lim limiter.Limiter, errorLog func(string, ...any)) (backend.Backend, error) {
|
||||
return f.openFn(ctx, *cfg.(*C), rt, lim, errorLog)
|
||||
}
|
||||
|
||||
@@ -69,17 +69,17 @@ func NewHTTPBackendFactory[C any, T backend.Backend](
|
||||
scheme string,
|
||||
parseConfigFn func(s string) (*C, error),
|
||||
stripPasswordFn func(s string) string,
|
||||
createFn func(ctx context.Context, cfg C, rt http.RoundTripper, errorLog func(string, ...interface{})) (T, error),
|
||||
openFn func(ctx context.Context, cfg C, rt http.RoundTripper, errorLog func(string, ...interface{})) (T, error)) Factory {
|
||||
createFn func(ctx context.Context, cfg C, rt http.RoundTripper, errorLog func(string, ...any)) (T, error),
|
||||
openFn func(ctx context.Context, cfg C, rt http.RoundTripper, errorLog func(string, ...any)) (T, error)) Factory {
|
||||
|
||||
return &genericBackendFactory[C, T]{
|
||||
scheme: scheme,
|
||||
parseConfigFn: parseConfigFn,
|
||||
stripPasswordFn: stripPasswordFn,
|
||||
createFn: func(ctx context.Context, cfg C, rt http.RoundTripper, _ limiter.Limiter, errorLog func(string, ...interface{})) (T, error) {
|
||||
createFn: func(ctx context.Context, cfg C, rt http.RoundTripper, _ limiter.Limiter, errorLog func(string, ...any)) (T, error) {
|
||||
return createFn(ctx, cfg, rt, errorLog)
|
||||
},
|
||||
openFn: func(ctx context.Context, cfg C, rt http.RoundTripper, _ limiter.Limiter, errorLog func(string, ...interface{})) (T, error) {
|
||||
openFn: func(ctx context.Context, cfg C, rt http.RoundTripper, _ limiter.Limiter, errorLog func(string, ...any)) (T, error) {
|
||||
return openFn(ctx, cfg, rt, errorLog)
|
||||
},
|
||||
}
|
||||
@@ -89,17 +89,17 @@ func NewLimitedBackendFactory[C any, T backend.Backend](
|
||||
scheme string,
|
||||
parseConfigFn func(s string) (*C, error),
|
||||
stripPasswordFn func(s string) string,
|
||||
createFn func(ctx context.Context, cfg C, lim limiter.Limiter, errorLog func(string, ...interface{})) (T, error),
|
||||
openFn func(ctx context.Context, cfg C, lim limiter.Limiter, errorLog func(string, ...interface{})) (T, error)) Factory {
|
||||
createFn func(ctx context.Context, cfg C, lim limiter.Limiter, errorLog func(string, ...any)) (T, error),
|
||||
openFn func(ctx context.Context, cfg C, lim limiter.Limiter, errorLog func(string, ...any)) (T, error)) Factory {
|
||||
|
||||
return &genericBackendFactory[C, T]{
|
||||
scheme: scheme,
|
||||
parseConfigFn: parseConfigFn,
|
||||
stripPasswordFn: stripPasswordFn,
|
||||
createFn: func(ctx context.Context, cfg C, _ http.RoundTripper, lim limiter.Limiter, errorLog func(string, ...interface{})) (T, error) {
|
||||
createFn: func(ctx context.Context, cfg C, _ http.RoundTripper, lim limiter.Limiter, errorLog func(string, ...any)) (T, error) {
|
||||
return createFn(ctx, cfg, lim, errorLog)
|
||||
},
|
||||
openFn: func(ctx context.Context, cfg C, _ http.RoundTripper, lim limiter.Limiter, errorLog func(string, ...interface{})) (T, error) {
|
||||
openFn: func(ctx context.Context, cfg C, _ http.RoundTripper, lim limiter.Limiter, errorLog func(string, ...any)) (T, error) {
|
||||
return openFn(ctx, cfg, lim, errorLog)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -33,10 +33,10 @@ func NewFactory() location.Factory {
|
||||
return &struct{}{}, nil
|
||||
},
|
||||
location.NoPassword,
|
||||
func(_ context.Context, _ struct{}, _ http.RoundTripper, _ func(string, ...interface{})) (*MemoryBackend, error) {
|
||||
func(_ context.Context, _ struct{}, _ http.RoundTripper, _ func(string, ...any)) (*MemoryBackend, error) {
|
||||
return be, nil
|
||||
},
|
||||
func(_ context.Context, _ struct{}, _ http.RoundTripper, _ func(string, ...interface{})) (*MemoryBackend, error) {
|
||||
func(_ context.Context, _ struct{}, _ http.RoundTripper, _ func(string, ...any)) (*MemoryBackend, error) {
|
||||
return be, nil
|
||||
},
|
||||
)
|
||||
|
||||
@@ -44,7 +44,7 @@ func NewFactory() location.Factory {
|
||||
}
|
||||
|
||||
// run starts command with args and initializes the StdioConn.
|
||||
func run(errorLog func(string, ...interface{}), command string, args ...string) (*StdioConn, *sync.WaitGroup, chan struct{}, func() error, error) {
|
||||
func run(errorLog func(string, ...any), command string, args ...string) (*StdioConn, *sync.WaitGroup, chan struct{}, func() error, error) {
|
||||
cmd := exec.Command(command, args...)
|
||||
|
||||
p, err := cmd.StderrPipe()
|
||||
@@ -56,16 +56,14 @@ func run(errorLog func(string, ...interface{}), command string, args ...string)
|
||||
waitCh := make(chan struct{})
|
||||
|
||||
// start goroutine to add a prefix to all messages printed by to stderr by rclone
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
wg.Go(func() {
|
||||
defer close(waitCh)
|
||||
sc := bufio.NewScanner(p)
|
||||
for sc.Scan() {
|
||||
errorLog("rclone: %v\n", sc.Text())
|
||||
}
|
||||
debug.Log("command has exited, closing waitCh")
|
||||
}()
|
||||
})
|
||||
|
||||
r, stdin, err := os.Pipe()
|
||||
if err != nil {
|
||||
@@ -141,7 +139,7 @@ func wrapConn(c *StdioConn, lim limiter.Limiter) *wrappedConn {
|
||||
}
|
||||
|
||||
// New initializes a Backend and starts the process.
|
||||
func newBackend(ctx context.Context, cfg Config, lim limiter.Limiter, errorLog func(string, ...interface{})) (*rclone, error) {
|
||||
func newBackend(ctx context.Context, cfg Config, lim limiter.Limiter, errorLog func(string, ...any)) (*rclone, error) {
|
||||
var (
|
||||
args []string
|
||||
err error
|
||||
@@ -207,9 +205,7 @@ func newBackend(ctx context.Context, cfg Config, lim limiter.Limiter, errorLog f
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
wg.Go(func() {
|
||||
<-waitCh
|
||||
cancel()
|
||||
|
||||
@@ -219,7 +215,7 @@ func newBackend(ctx context.Context, cfg Config, lim limiter.Limiter, errorLog f
|
||||
be.waitResult = err
|
||||
// close our side of the pipes to rclone, ignore errors
|
||||
_ = stdioConn.CloseAll()
|
||||
}()
|
||||
})
|
||||
|
||||
// send an HTTP request to the base URL, see if the server is there
|
||||
client := http.Client{
|
||||
@@ -270,7 +266,7 @@ func newBackend(ctx context.Context, cfg Config, lim limiter.Limiter, errorLog f
|
||||
}
|
||||
|
||||
// Open starts an rclone process with the given config.
|
||||
func Open(ctx context.Context, cfg Config, lim limiter.Limiter, errorLog func(string, ...interface{})) (backend.Backend, error) {
|
||||
func Open(ctx context.Context, cfg Config, lim limiter.Limiter, errorLog func(string, ...any)) (backend.Backend, error) {
|
||||
be, err := newBackend(ctx, cfg, lim, errorLog)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -297,7 +293,7 @@ func Open(ctx context.Context, cfg Config, lim limiter.Limiter, errorLog func(st
|
||||
}
|
||||
|
||||
// Create initializes a new restic repo with rclone.
|
||||
func Create(ctx context.Context, cfg Config, lim limiter.Limiter, errorLog func(string, ...interface{})) (backend.Backend, error) {
|
||||
func Create(ctx context.Context, cfg Config, lim limiter.Limiter, errorLog func(string, ...any)) (backend.Backend, error) {
|
||||
be, err := newBackend(ctx, cfg, lim, errorLog)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -32,7 +32,7 @@ func TestRcloneExit(t *testing.T) {
|
||||
rtest.OK(t, err)
|
||||
t.Log("killed rclone")
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
for range 10 {
|
||||
_, err = be.Stat(context.TODO(), backend.Handle{
|
||||
Name: "foo",
|
||||
Type: backend.PackFile,
|
||||
|
||||
@@ -55,7 +55,7 @@ const (
|
||||
)
|
||||
|
||||
// Open opens the REST backend with the given config.
|
||||
func Open(_ context.Context, cfg Config, rt http.RoundTripper, _ func(string, ...interface{})) (*Backend, error) {
|
||||
func Open(_ context.Context, cfg Config, rt http.RoundTripper, _ func(string, ...any)) (*Backend, error) {
|
||||
// use url without trailing slash for layout
|
||||
url := cfg.URL.String()
|
||||
if url[len(url)-1] == '/' {
|
||||
@@ -84,7 +84,7 @@ func drainAndClose(resp *http.Response) error {
|
||||
}
|
||||
|
||||
// Create creates a new REST on server configured in config.
|
||||
func Create(ctx context.Context, cfg Config, rt http.RoundTripper, errorLog func(string, ...interface{})) (*Backend, error) {
|
||||
func Create(ctx context.Context, cfg Config, rt http.RoundTripper, errorLog func(string, ...any)) (*Backend, error) {
|
||||
be, err := Open(ctx, cfg, rt, errorLog)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -170,8 +170,7 @@ func TestBackendREST(t *testing.T) {
|
||||
}
|
||||
}()
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
ctx := t.Context()
|
||||
|
||||
dir := rtest.TempDir(t)
|
||||
serverURL, cleanup := runRESTServer(ctx, t, dir, ":0")
|
||||
@@ -195,8 +194,7 @@ func TestBackendRESTExternalServer(t *testing.T) {
|
||||
}
|
||||
|
||||
func BenchmarkBackendREST(t *testing.B) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
ctx := t.Context()
|
||||
|
||||
dir := rtest.TempDir(t)
|
||||
serverURL, cleanup := runRESTServer(ctx, t, dir, ":0")
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
package rest_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"path"
|
||||
"testing"
|
||||
@@ -18,8 +17,7 @@ func TestBackendRESTWithUnixSocket(t *testing.T) {
|
||||
}
|
||||
}()
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
ctx := t.Context()
|
||||
|
||||
dir := rtest.TempDir(t)
|
||||
serverURL, cleanup := runRESTServer(ctx, t, path.Join(dir, "data"), fmt.Sprintf("unix:%s", path.Join(dir, "sock")))
|
||||
|
||||
@@ -197,13 +197,13 @@ func getCredentials(cfg Config, tr http.RoundTripper) (*credentials.Credentials,
|
||||
|
||||
// Open opens the S3 backend at bucket and region. The bucket is created if it
|
||||
// does not exist yet.
|
||||
func Open(_ context.Context, cfg Config, rt http.RoundTripper, _ func(string, ...interface{})) (backend.Backend, error) {
|
||||
func Open(_ context.Context, cfg Config, rt http.RoundTripper, _ func(string, ...any)) (backend.Backend, error) {
|
||||
return open(cfg, rt)
|
||||
}
|
||||
|
||||
// Create opens the S3 backend at bucket and region and creates the bucket if
|
||||
// it does not exist yet.
|
||||
func Create(ctx context.Context, cfg Config, rt http.RoundTripper, _ func(string, ...interface{})) (backend.Backend, error) {
|
||||
func Create(ctx context.Context, cfg Config, rt http.RoundTripper, _ func(string, ...any)) (backend.Backend, error) {
|
||||
be, err := open(cfg, rt)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "open")
|
||||
|
||||
@@ -51,7 +51,7 @@ func runMinio(ctx context.Context, t testing.TB, dir, key, secret string) func()
|
||||
|
||||
// wait until the TCP port is reachable
|
||||
var success bool
|
||||
for i := 0; i < 100; i++ {
|
||||
for range 100 {
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
|
||||
c, err := net.Dial("tcp", "localhost:9000")
|
||||
@@ -117,8 +117,8 @@ func newMinioTestSuite(t testing.TB) (*test.Suite[s3.Config], func()) {
|
||||
return &cfg, nil
|
||||
},
|
||||
|
||||
Factory: location.NewHTTPBackendFactory("s3", s3.ParseConfig, location.NoPassword, func(ctx context.Context, cfg s3.Config, rt http.RoundTripper, errorLog func(string, ...interface{})) (be backend.Backend, err error) {
|
||||
for i := 0; i < 50; i++ {
|
||||
Factory: location.NewHTTPBackendFactory("s3", s3.ParseConfig, location.NoPassword, func(ctx context.Context, cfg s3.Config, rt http.RoundTripper, errorLog func(string, ...any)) (be backend.Backend, err error) {
|
||||
for i := range 50 {
|
||||
be, err = s3.Create(ctx, cfg, rt, errorLog)
|
||||
if err != nil {
|
||||
t.Logf("s3 open: try %d: error %v", i, err)
|
||||
|
||||
@@ -115,7 +115,7 @@ func concurrencyTester(t *testing.T, setup func(m *mock.Backend), handler func(b
|
||||
be := sema.NewBackend(m)
|
||||
|
||||
var wg errgroup.Group
|
||||
for i := 0; i < workerCount; i++ {
|
||||
for range workerCount {
|
||||
wg.Go(handler(be))
|
||||
}
|
||||
|
||||
@@ -225,12 +225,10 @@ func TestFreeze(t *testing.T) {
|
||||
|
||||
// Start Save call that should block
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
wg.Go(func() {
|
||||
h := backend.Handle{Type: backend.PackFile, Name: "foobar"}
|
||||
test.OK(t, be.Save(context.TODO(), h, nil))
|
||||
}()
|
||||
})
|
||||
|
||||
// check
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
|
||||
@@ -54,7 +54,7 @@ func NewFactory() location.Factory {
|
||||
return location.NewLimitedBackendFactory("sftp", ParseConfig, location.NoPassword, limiter.WrapBackendConstructor(Create), limiter.WrapBackendConstructor(Open))
|
||||
}
|
||||
|
||||
func startClient(cfg Config, errorLog func(string, ...interface{})) (*SFTP, error) {
|
||||
func startClient(cfg Config, errorLog func(string, ...any)) (*SFTP, error) {
|
||||
program, args, err := buildSSHCommand(cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -147,7 +147,7 @@ func (r *SFTP) clientError() error {
|
||||
|
||||
// Open opens an sftp backend as described by the config by running
|
||||
// "ssh" with the appropriate arguments (or cfg.Command, if set).
|
||||
func Open(_ context.Context, cfg Config, errorLog func(string, ...interface{})) (*SFTP, error) {
|
||||
func Open(_ context.Context, cfg Config, errorLog func(string, ...any)) (*SFTP, error) {
|
||||
debug.Log("open backend with config %#v", cfg)
|
||||
|
||||
sftp, err := startClient(cfg, errorLog)
|
||||
@@ -273,7 +273,7 @@ func buildSSHCommand(cfg Config) (cmd string, args []string, err error) {
|
||||
|
||||
// Create creates an sftp backend as described by the config by running "ssh"
|
||||
// with the appropriate arguments (or cfg.Command, if set).
|
||||
func Create(ctx context.Context, cfg Config, errorLog func(string, ...interface{})) (*SFTP, error) {
|
||||
func Create(ctx context.Context, cfg Config, errorLog func(string, ...any)) (*SFTP, error) {
|
||||
sftp, err := startClient(cfg, errorLog)
|
||||
if err != nil {
|
||||
debug.Log("unable to start program: %v", err)
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
)
|
||||
|
||||
func findSFTPServerBinary() string {
|
||||
for _, dir := range strings.Split(rtest.TestSFTPPath, ":") {
|
||||
for dir := range strings.SplitSeq(rtest.TestSFTPPath, ":") {
|
||||
testpath := filepath.Join(dir, "sftp-server")
|
||||
_, err := os.Stat(testpath)
|
||||
if !errors.Is(err, os.ErrNotExist) {
|
||||
@@ -82,7 +82,7 @@ func TestCreateSetsDirPermissions(t *testing.T) {
|
||||
|
||||
cfg := testConfig(filepath.Join(rtest.TempDir(t), "repo"))
|
||||
|
||||
be, err := sftp.Create(context.Background(), cfg, func(string, ...interface{}) {})
|
||||
be, err := sftp.Create(context.Background(), cfg, func(string, ...any) {})
|
||||
rtest.OK(t, err)
|
||||
defer func() { rtest.OK(t, be.Close()) }()
|
||||
|
||||
@@ -108,7 +108,7 @@ func TestSaveSetsDirPermissions(t *testing.T) {
|
||||
|
||||
cfg := testConfig(filepath.Join(rtest.TempDir(t), "repo"))
|
||||
|
||||
be, err := sftp.Create(context.Background(), cfg, func(string, ...interface{}) {})
|
||||
be, err := sftp.Create(context.Background(), cfg, func(string, ...any) {})
|
||||
rtest.OK(t, err)
|
||||
defer func() { rtest.OK(t, be.Close()) }()
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ func NewFactory() location.Factory {
|
||||
|
||||
// Open opens the swift backend at a container in region. The container is
|
||||
// created if it does not exist yet.
|
||||
func Open(ctx context.Context, cfg Config, rt http.RoundTripper, _ func(string, ...interface{})) (backend.Backend, error) {
|
||||
func Open(ctx context.Context, cfg Config, rt http.RoundTripper, _ func(string, ...any)) (backend.Backend, error) {
|
||||
debug.Log("config %#v", cfg)
|
||||
|
||||
be := &beSwift{
|
||||
@@ -202,7 +202,7 @@ func (be *beSwift) List(ctx context.Context, t backend.FileType, fn func(backend
|
||||
prefix += "/"
|
||||
|
||||
err := be.conn.ObjectsWalk(ctx, be.container, &swift.ObjectsOpts{Prefix: prefix},
|
||||
func(ctx context.Context, opts *swift.ObjectsOpts) (interface{}, error) {
|
||||
func(ctx context.Context, opts *swift.ObjectsOpts) (any, error) {
|
||||
newObjects, err := be.conn.Objects(ctx, be.container, opts)
|
||||
|
||||
if err != nil {
|
||||
|
||||
@@ -67,7 +67,7 @@ type testFunction struct {
|
||||
}
|
||||
|
||||
func (s *Suite[C]) testFuncs(t testing.TB) (funcs []testFunction) {
|
||||
tpe := reflect.TypeOf(s)
|
||||
tpe := reflect.TypeFor[*Suite[C]]()
|
||||
v := reflect.ValueOf(s)
|
||||
|
||||
for i := 0; i < tpe.NumMethod(); i++ {
|
||||
@@ -102,7 +102,7 @@ type benchmarkFunction struct {
|
||||
}
|
||||
|
||||
func (s *Suite[C]) benchmarkFuncs(t testing.TB) (funcs []benchmarkFunction) {
|
||||
tpe := reflect.TypeOf(s)
|
||||
tpe := reflect.TypeFor[*Suite[C]]()
|
||||
v := reflect.ValueOf(s)
|
||||
|
||||
for i := 0; i < tpe.NumMethod(); i++ {
|
||||
@@ -192,7 +192,7 @@ func (s *Suite[C]) open(t testing.TB) backend.Backend {
|
||||
t.Fatalf("cannot create transport for tests: %v", err)
|
||||
}
|
||||
|
||||
be, err := s.Factory.Open(context.TODO(), s.Config, tr, nil, func(string, ...interface{}) {})
|
||||
be, err := s.Factory.Open(context.TODO(), s.Config, tr, nil, func(string, ...any) {})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -277,7 +277,7 @@ func (s *Suite[C]) TestList(t *testing.T) {
|
||||
var m sync.Mutex
|
||||
|
||||
wg, ctx := errgroup.WithContext(context.TODO())
|
||||
for i := 0; i < numTestFiles; i++ {
|
||||
for range numTestFiles {
|
||||
data := test.Random(random.Int(), random.Intn(100)+55)
|
||||
wg.Go(func() error {
|
||||
id := restic.Hash(data)
|
||||
@@ -354,8 +354,8 @@ func (s *Suite[C]) TestListCancel(t *testing.T) {
|
||||
|
||||
testFiles := make([]backend.Handle, 0, numTestFiles)
|
||||
|
||||
for i := 0; i < numTestFiles; i++ {
|
||||
data := []byte(fmt.Sprintf("random test blob %v", i))
|
||||
for i := range numTestFiles {
|
||||
data := fmt.Appendf(nil, "random test blob %v", i)
|
||||
id := restic.Hash(data)
|
||||
h := backend.Handle{Type: backend.PackFile, Name: id.String()}
|
||||
err := b.Save(context.TODO(), h, backend.NewByteReader(data, b.Hasher()))
|
||||
@@ -768,7 +768,7 @@ func (s *Suite[C]) delayedRemove(t testing.TB, be backend.Backend, handles ...ba
|
||||
func delayedList(t testing.TB, b backend.Backend, tpe backend.FileType, max int, maxwait time.Duration) restic.IDs {
|
||||
list := restic.NewIDSet()
|
||||
start := time.Now()
|
||||
for i := 0; i < max; i++ {
|
||||
for range max {
|
||||
err := b.List(context.TODO(), tpe, func(fi backend.FileInfo) error {
|
||||
id := restic.TestParseID(fi.Name)
|
||||
list.Insert(id)
|
||||
|
||||
@@ -94,7 +94,7 @@ func TestCacheGetOrCompute(t *testing.T) {
|
||||
calls := make(chan struct{}, 10)
|
||||
|
||||
// start a bunch of blocking goroutines
|
||||
for i := 0; i < 10; i++ {
|
||||
for range 10 {
|
||||
wg.Go(func() error {
|
||||
buf, err := c.GetOrCompute(id2, func() ([]byte, error) {
|
||||
// block to ensure that multiple requests are waiting in parallel
|
||||
|
||||
@@ -609,7 +609,7 @@ func benchmarkSnapshotScaling(t *testing.B, newSnapshots int) {
|
||||
|
||||
treeID := sn2.Tree
|
||||
|
||||
for i := 0; i < newSnapshots; i++ {
|
||||
for i := range newSnapshots {
|
||||
sn, err := data.NewSnapshot([]string{"test" + strconv.Itoa(i)}, nil, "", time.Now())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -88,7 +88,7 @@ func TestFindUsedBlobs(t *testing.T) {
|
||||
repo := repository.TestRepository(t)
|
||||
|
||||
var snapshots []*data.Snapshot
|
||||
for i := 0; i < findTestSnapshots; i++ {
|
||||
for i := range findTestSnapshots {
|
||||
sn := data.TestCreateSnapshot(t, repo, findTestTime.Add(time.Duration(i)*time.Second), findTestDepth)
|
||||
t.Logf("snapshot %v saved, tree %v", sn.ID().Str(), sn.Tree.Str())
|
||||
snapshots = append(snapshots, sn)
|
||||
@@ -131,7 +131,7 @@ func TestMultiFindUsedBlobs(t *testing.T) {
|
||||
repo := repository.TestRepository(t)
|
||||
|
||||
var snapshotTrees restic.IDs
|
||||
for i := 0; i < findTestSnapshots; i++ {
|
||||
for i := range findTestSnapshots {
|
||||
sn := data.TestCreateSnapshot(t, repo, findTestTime.Add(time.Duration(i)*time.Second), findTestDepth)
|
||||
t.Logf("snapshot %v saved, tree %v", sn.ID().Str(), sn.Tree.Str())
|
||||
snapshotTrees = append(snapshotTrees, *sn.Tree)
|
||||
|
||||
@@ -86,9 +86,9 @@ type Node struct {
|
||||
Name string `json:"name"`
|
||||
Type NodeType `json:"type"`
|
||||
Mode os.FileMode `json:"mode,omitempty"`
|
||||
ModTime time.Time `json:"mtime,omitempty"`
|
||||
AccessTime time.Time `json:"atime,omitempty"`
|
||||
ChangeTime time.Time `json:"ctime,omitempty"`
|
||||
ModTime time.Time `json:"mtime"`
|
||||
AccessTime time.Time `json:"atime"`
|
||||
ChangeTime time.Time `json:"ctime"`
|
||||
UID uint32 `json:"uid"`
|
||||
GID uint32 `json:"gid"`
|
||||
User string `json:"user,omitempty"`
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -174,12 +175,7 @@ func (sn *Snapshot) RemoveTags(removeTags []string) (changed bool) {
|
||||
}
|
||||
|
||||
func (sn *Snapshot) hasTag(tag string) bool {
|
||||
for _, snTag := range sn.Tags {
|
||||
if tag == snTag {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return slices.Contains(sn.Tags, tag)
|
||||
}
|
||||
|
||||
// HasTags returns true if the snapshot has all the tags in l.
|
||||
@@ -240,13 +236,7 @@ func (sn *Snapshot) HasHostname(hostnames []string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
for _, hostname := range hostnames {
|
||||
if sn.Hostname == hostname {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
return slices.Contains(hostnames, sn.Hostname)
|
||||
}
|
||||
|
||||
// Snapshots is a list of snapshots.
|
||||
|
||||
@@ -15,7 +15,7 @@ type SnapshotGroupByOptions struct {
|
||||
|
||||
func splitSnapshotGroupBy(s string) (SnapshotGroupByOptions, error) {
|
||||
var l SnapshotGroupByOptions
|
||||
for _, option := range strings.Split(s, ",") {
|
||||
for option := range strings.SplitSeq(s, ",") {
|
||||
switch option {
|
||||
case "host", "hosts":
|
||||
l.Host = true
|
||||
|
||||
@@ -12,7 +12,7 @@ type TagList []string
|
||||
// need to be separated by commas. Whitespace is stripped around the individual
|
||||
// tags.
|
||||
func splitTagList(s string) (l TagList) {
|
||||
for _, t := range strings.Split(s, ",") {
|
||||
for t := range strings.SplitSeq(s, ",") {
|
||||
l = append(l, strings.TrimSpace(t))
|
||||
}
|
||||
return l
|
||||
|
||||
@@ -75,7 +75,7 @@ func (fs *fakeFileSystem) saveTree(ctx context.Context, uploader restic.BlobSave
|
||||
numNodes := int(rnd.Int63() % maxNodes)
|
||||
|
||||
var nodes []*Node
|
||||
for i := 0; i < numNodes; i++ {
|
||||
for i := range numNodes {
|
||||
// randomly select the type of the node, either tree (p = 1/4) or file (p = 3/4).
|
||||
if depth > 1 && rnd.Int63()%4 == 0 {
|
||||
treeSeed := rnd.Int63() % maxSeed
|
||||
|
||||
@@ -20,7 +20,7 @@ const (
|
||||
|
||||
func TestCreateSnapshot(t *testing.T) {
|
||||
repo := repository.TestRepository(t)
|
||||
for i := 0; i < testCreateSnapshots; i++ {
|
||||
for i := range testCreateSnapshots {
|
||||
data.TestCreateSnapshot(t, repo, testSnapshotTime.Add(time.Duration(i)*time.Second), testDepth)
|
||||
}
|
||||
|
||||
|
||||
@@ -201,7 +201,7 @@ func StreamTrees(
|
||||
// decoding a tree can take quite some time such that this can be both CPU- or IO-bound
|
||||
// one extra worker to handle huge tree blobs
|
||||
workerCount := int(repo.Connections()) + runtime.GOMAXPROCS(0) + 1
|
||||
for i := 0; i < workerCount; i++ {
|
||||
for i := range workerCount {
|
||||
workerLoaderChan := loaderChan
|
||||
if i == 0 {
|
||||
workerLoaderChan = hugeTreeChan
|
||||
|
||||
@@ -61,7 +61,7 @@ func parseFilter(envname string, pad func(string) string) map[string]bool {
|
||||
return filter
|
||||
}
|
||||
|
||||
for _, fn := range strings.Split(env, ",") {
|
||||
for fn := range strings.SplitSeq(env, ",") {
|
||||
t := pad(strings.TrimSpace(fn))
|
||||
val := true
|
||||
switch t[0] {
|
||||
@@ -161,7 +161,7 @@ func checkFilter(filter map[string]bool, key string) bool {
|
||||
}
|
||||
|
||||
// Log prints a message to the debug log (if debug is enabled).
|
||||
func Log(f string, args ...interface{}) {
|
||||
func Log(f string, args ...any) {
|
||||
if !opts.isEnabled {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package debug
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"maps"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"os"
|
||||
@@ -77,9 +78,7 @@ func redactHeader(header http.Header) map[string][]string {
|
||||
}
|
||||
|
||||
func restoreHeader(header http.Header, origHeaders map[string][]string) {
|
||||
for hdr, val := range origHeaders {
|
||||
header[hdr] = val
|
||||
}
|
||||
maps.Copy(header, origHeaders)
|
||||
}
|
||||
|
||||
func (tr loggingRoundTripper) RoundTrip(req *http.Request) (res *http.Response, err error) {
|
||||
|
||||
@@ -2,7 +2,6 @@ package dump
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/restic/restic/internal/archiver"
|
||||
@@ -80,8 +79,7 @@ func WriteTest(t *testing.T, format string, cd CheckDump) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
ctx := t.Context()
|
||||
|
||||
tmpdir, repo, be := prepareTempdirRepoSrc(t, tt.args)
|
||||
arch := archiver.New(repo, fs.Track{FS: fs.NewLocal()}, archiver.Options{})
|
||||
|
||||
@@ -30,7 +30,7 @@ var WithStack = errors.WithStack
|
||||
|
||||
// As finds the first error in err's tree that matches target, and if one is found,
|
||||
// sets target to that error value and returns true. Otherwise, it returns false.
|
||||
func As(err error, tgt interface{}) bool { return stderrors.As(err, tgt) }
|
||||
func As(err error, tgt any) bool { return stderrors.As(err, tgt) }
|
||||
|
||||
// Is reports whether any error in err's tree matches target.
|
||||
func Is(x, y error) bool { return stderrors.Is(x, y) }
|
||||
|
||||
@@ -33,7 +33,7 @@ func Fatal(s string) error {
|
||||
}
|
||||
|
||||
// Fatalf returns an error that is marked fatal, preserving an underlying error if passed.
|
||||
func Fatalf(s string, data ...interface{}) error {
|
||||
func Fatalf(s string, data ...any) error {
|
||||
// Use the last error found.
|
||||
var underlyingErr error
|
||||
for i := len(data) - 1; i >= 0; i-- {
|
||||
|
||||
@@ -64,7 +64,7 @@ func (f *FlagSet) Apply(flags string, logWarning func(string)) error {
|
||||
|
||||
selection := make(map[string]bool)
|
||||
|
||||
for _, flag := range strings.Split(flags, ",") {
|
||||
for flag := range strings.SplitSeq(flags, ",") {
|
||||
parts := strings.SplitN(flag, "=", 2)
|
||||
|
||||
name := parts[0]
|
||||
|
||||
@@ -20,7 +20,7 @@ type RejectByNameFunc func(path string) bool
|
||||
|
||||
// RejectByPattern returns a RejectByNameFunc which rejects files that match
|
||||
// one of the patterns.
|
||||
func RejectByPattern(patterns []string, warnf func(msg string, args ...interface{})) RejectByNameFunc {
|
||||
func RejectByPattern(patterns []string, warnf func(msg string, args ...any)) RejectByNameFunc {
|
||||
parsedPatterns := ParsePatterns(patterns)
|
||||
return func(item string) bool {
|
||||
matched, err := List(parsedPatterns, item)
|
||||
@@ -38,7 +38,7 @@ func RejectByPattern(patterns []string, warnf func(msg string, args ...interface
|
||||
}
|
||||
|
||||
// RejectByInsensitivePattern is like RejectByPattern but case insensitive.
|
||||
func RejectByInsensitivePattern(patterns []string, warnf func(msg string, args ...interface{})) RejectByNameFunc {
|
||||
func RejectByInsensitivePattern(patterns []string, warnf func(msg string, args ...any)) RejectByNameFunc {
|
||||
lowerPatterns := make([]string, len(patterns))
|
||||
for index, path := range patterns {
|
||||
lowerPatterns[index] = strings.ToLower(path)
|
||||
@@ -115,7 +115,7 @@ func (opts *ExcludePatternOptions) Empty() bool {
|
||||
return len(opts.Excludes) == 0 && len(opts.InsensitiveExcludes) == 0 && len(opts.ExcludeFiles) == 0 && len(opts.InsensitiveExcludeFiles) == 0
|
||||
}
|
||||
|
||||
func (opts ExcludePatternOptions) CollectPatterns(warnf func(msg string, args ...interface{})) ([]RejectByNameFunc, error) {
|
||||
func (opts ExcludePatternOptions) CollectPatterns(warnf func(msg string, args ...any)) ([]RejectByNameFunc, error) {
|
||||
var fs []RejectByNameFunc
|
||||
// add patterns from file
|
||||
if len(opts.ExcludeFiles) > 0 {
|
||||
|
||||
@@ -131,11 +131,7 @@ func childMatch(pattern Pattern, strs []string) (matched bool, err error) {
|
||||
|
||||
// match path against absolute pattern prefix
|
||||
l := 0
|
||||
if len(strs) > len(pattern.parts) {
|
||||
l = len(pattern.parts)
|
||||
} else {
|
||||
l = len(strs)
|
||||
}
|
||||
l = min(len(strs), len(pattern.parts))
|
||||
return match(Pattern{pattern.original, pattern.parts[0:l], pattern.isNegated}, strs)
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ func (opts *IncludePatternOptions) Empty() bool {
|
||||
return len(opts.Includes) == 0 && len(opts.InsensitiveIncludes) == 0 && len(opts.IncludeFiles) == 0 && len(opts.InsensitiveIncludeFiles) == 0
|
||||
}
|
||||
|
||||
func (opts IncludePatternOptions) CollectPatterns(warnf func(msg string, args ...interface{})) ([]IncludeByNameFunc, error) {
|
||||
func (opts IncludePatternOptions) CollectPatterns(warnf func(msg string, args ...any)) ([]IncludeByNameFunc, error) {
|
||||
var fs []IncludeByNameFunc
|
||||
if len(opts.IncludeFiles) > 0 {
|
||||
includePatterns, err := readPatternsFromFiles(opts.IncludeFiles)
|
||||
@@ -77,7 +77,7 @@ func (opts IncludePatternOptions) CollectPatterns(warnf func(msg string, args ..
|
||||
|
||||
// IncludeByPattern returns an IncludeByNameFunc which includes files that match
|
||||
// one of the patterns.
|
||||
func IncludeByPattern(patterns []string, warnf func(msg string, args ...interface{})) IncludeByNameFunc {
|
||||
func IncludeByPattern(patterns []string, warnf func(msg string, args ...any)) IncludeByNameFunc {
|
||||
parsedPatterns := ParsePatterns(patterns)
|
||||
return func(item string) (matched bool, childMayMatch bool) {
|
||||
matched, childMayMatch, err := ListWithChild(parsedPatterns, item)
|
||||
@@ -91,7 +91,7 @@ func IncludeByPattern(patterns []string, warnf func(msg string, args ...interfac
|
||||
|
||||
// IncludeByInsensitivePattern returns an IncludeByNameFunc which includes files that match
|
||||
// one of the patterns, ignoring the casing of the filenames.
|
||||
func IncludeByInsensitivePattern(patterns []string, warnf func(msg string, args ...interface{})) IncludeByNameFunc {
|
||||
func IncludeByInsensitivePattern(patterns []string, warnf func(msg string, args ...any)) IncludeByNameFunc {
|
||||
lowerPatterns := make([]string, len(patterns))
|
||||
for index, path := range patterns {
|
||||
lowerPatterns[index] = strings.ToLower(path)
|
||||
|
||||
@@ -42,7 +42,7 @@ func ParseVSSConfig(o options.Options) (VSSConfig, error) {
|
||||
type ErrorHandler func(item string, err error)
|
||||
|
||||
// MessageHandler is used to report errors/messages via callbacks.
|
||||
type MessageHandler func(msg string, args ...interface{})
|
||||
type MessageHandler func(msg string, args ...any)
|
||||
|
||||
// volumeFilter is used to filter volumes by their mount point or GUID path.
|
||||
type volumeFilter func(volume string) bool
|
||||
@@ -72,7 +72,7 @@ func parseMountPoints(list string, msgError ErrorHandler) (volumes map[string]st
|
||||
if list == "" {
|
||||
return
|
||||
}
|
||||
for _, s := range strings.Split(list, ";") {
|
||||
for s := range strings.SplitSeq(list, ";") {
|
||||
if v, err := getVolumeNameForVolumeMountPoint(s); err != nil {
|
||||
msgError(s, errors.Errorf("failed to parse vss.exclude-volumes [%s]: %s", s, err))
|
||||
} else {
|
||||
|
||||
@@ -28,7 +28,7 @@ type commandReader struct {
|
||||
alreadyClosedReadErr error
|
||||
}
|
||||
|
||||
func NewCommandReader(ctx context.Context, args []string, errorOutput func(msg string, args ...interface{})) (io.ReadCloser, error) {
|
||||
func NewCommandReader(ctx context.Context, args []string, errorOutput func(msg string, args ...any)) (io.ReadCloser, error) {
|
||||
if len(args) == 0 {
|
||||
return nil, fmt.Errorf("no command was specified as argument")
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
func TestCommandReaderSuccess(t *testing.T) {
|
||||
reader, err := fs.NewCommandReader(context.TODO(), []string{"true"}, func(msg string, args ...interface{}) {})
|
||||
reader, err := fs.NewCommandReader(context.TODO(), []string{"true"}, func(msg string, args ...any) {})
|
||||
test.OK(t, err)
|
||||
|
||||
_, err = io.Copy(io.Discard, reader)
|
||||
@@ -23,7 +23,7 @@ func TestCommandReaderSuccess(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCommandReaderFail(t *testing.T) {
|
||||
reader, err := fs.NewCommandReader(context.TODO(), []string{"false"}, func(msg string, args ...interface{}) {})
|
||||
reader, err := fs.NewCommandReader(context.TODO(), []string{"false"}, func(msg string, args ...any) {})
|
||||
test.OK(t, err)
|
||||
|
||||
_, err = io.Copy(io.Discard, reader)
|
||||
@@ -31,17 +31,17 @@ func TestCommandReaderFail(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCommandReaderInvalid(t *testing.T) {
|
||||
_, err := fs.NewCommandReader(context.TODO(), []string{"w54fy098hj7fy5twijouytfrj098y645wr"}, func(msg string, args ...interface{}) {})
|
||||
_, err := fs.NewCommandReader(context.TODO(), []string{"w54fy098hj7fy5twijouytfrj098y645wr"}, func(msg string, args ...any) {})
|
||||
test.Assert(t, err != nil, "missing error")
|
||||
}
|
||||
|
||||
func TestCommandReaderEmptyArgs(t *testing.T) {
|
||||
_, err := fs.NewCommandReader(context.TODO(), []string{}, func(msg string, args ...interface{}) {})
|
||||
_, err := fs.NewCommandReader(context.TODO(), []string{}, func(msg string, args ...any) {})
|
||||
test.Assert(t, err != nil, "missing error")
|
||||
}
|
||||
|
||||
func TestCommandReaderOutput(t *testing.T) {
|
||||
reader, err := fs.NewCommandReader(context.TODO(), []string{"echo", "hello world"}, func(msg string, args ...interface{}) {})
|
||||
reader, err := fs.NewCommandReader(context.TODO(), []string{"echo", "hello world"}, func(msg string, args ...any) {})
|
||||
test.OK(t, err)
|
||||
|
||||
var buf bytes.Buffer
|
||||
@@ -56,7 +56,7 @@ func TestCommandReaderOutput(t *testing.T) {
|
||||
func TestCommandReaderQuickClose(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second)
|
||||
defer cancel()
|
||||
reader, err := fs.NewCommandReader(ctx, []string{"sleep", "3600"}, func(msg string, args ...interface{}) {})
|
||||
reader, err := fs.NewCommandReader(ctx, []string{"sleep", "3600"}, func(msg string, args ...any) {})
|
||||
test.OK(t, err)
|
||||
|
||||
// test that close returns before the context expires
|
||||
|
||||
@@ -198,7 +198,7 @@ func TestNodeRestoreAt(t *testing.T) {
|
||||
// Update the tests to use UPPER case xattr names for windows.
|
||||
extAttrArr := test.ExtendedAttributes
|
||||
// Iterate through the array using pointers
|
||||
for i := 0; i < len(extAttrArr); i++ {
|
||||
for i := range extAttrArr {
|
||||
extAttrArr[i].Name = strings.ToUpper(extAttrArr[i].Name)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ func TestOverwriteXattrWithSelectFilter(t *testing.T) {
|
||||
file := filepath.Join(dir, "file2")
|
||||
rtest.OK(t, os.WriteFile(file, []byte("hello world"), 0o600))
|
||||
|
||||
noopWarnf := func(_ string, _ ...interface{}) {}
|
||||
noopWarnf := func(_ string, _ ...any) {}
|
||||
|
||||
// Set a filter as if the user passed in --include-xattr user.*
|
||||
xattrSelectFilter1 := func(xattrName string) bool {
|
||||
|
||||
@@ -69,8 +69,7 @@ func loadTree(t testing.TB, repo restic.Loader, id restic.ID) data.TreeNodeItera
|
||||
func TestFuseFile(t *testing.T) {
|
||||
repo := repository.TestRepository(t)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
ctx := t.Context()
|
||||
|
||||
timestamp, err := time.Parse(time.RFC3339, "2017-01-24T10:42:56+01:00")
|
||||
rtest.OK(t, err)
|
||||
@@ -134,7 +133,7 @@ func TestFuseFile(t *testing.T) {
|
||||
rtest.Equals(t, node.Size, attr.Size)
|
||||
rtest.Equals(t, (node.Size/uint64(attr.BlockSize))+1, attr.Blocks)
|
||||
|
||||
for i := 0; i < 200; i++ {
|
||||
for i := range 200 {
|
||||
offset := rand.Intn(int(filesize))
|
||||
length := rand.Intn(int(filesize)-offset) + 100
|
||||
|
||||
|
||||
@@ -522,7 +522,7 @@ func innerOpenBackend(ctx context.Context, s string, gopts Options, opts options
|
||||
}
|
||||
|
||||
// parseConfig parses the repository location and extended options and returns the scheme and configuration.
|
||||
func parseConfig(backends *location.Registry, s string, opts options.Options) (string, interface{}, error) {
|
||||
func parseConfig(backends *location.Registry, s string, opts options.Options) (string, any, error) {
|
||||
loc, err := location.Parse(backends, s)
|
||||
if err != nil {
|
||||
return "", nil, errors.Fatalf("parsing repository location failed: %v", err)
|
||||
@@ -558,7 +558,7 @@ func setupTransport(gopts Options) (http.RoundTripper, limiter.Limiter, error) {
|
||||
}
|
||||
|
||||
// createOrOpenBackend creates or opens a backend using the appropriate factory method.
|
||||
func createOrOpenBackend(ctx context.Context, scheme string, cfg interface{}, rt http.RoundTripper, lim limiter.Limiter, gopts Options, s string, create bool, printer restic.Printer) (backend.Backend, error) {
|
||||
func createOrOpenBackend(ctx context.Context, scheme string, cfg any, rt http.RoundTripper, lim limiter.Limiter, gopts Options, s string, create bool, printer restic.Printer) (backend.Backend, error) {
|
||||
factory := gopts.Backends.Lookup(scheme)
|
||||
if factory == nil {
|
||||
return nil, errors.Fatalf("invalid backend: %q", scheme)
|
||||
|
||||
@@ -16,7 +16,7 @@ type Options map[string]string
|
||||
var opts []Help
|
||||
|
||||
// Register allows registering options so that they can be listed with List.
|
||||
func Register(ns string, cfg interface{}) {
|
||||
func Register(ns string, cfg any) {
|
||||
opts = appendAllOptions(opts, ns, cfg)
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ func List() (list []Help) {
|
||||
}
|
||||
|
||||
// appendAllOptions appends all options in cfg to opts, sorted by namespace.
|
||||
func appendAllOptions(opts []Help, ns string, cfg interface{}) []Help {
|
||||
func appendAllOptions(opts []Help, ns string, cfg any) []Help {
|
||||
for _, opt := range listOptions(cfg) {
|
||||
opt.Namespace = ns
|
||||
opts = append(opts, opt)
|
||||
@@ -39,7 +39,7 @@ func appendAllOptions(opts []Help, ns string, cfg interface{}) []Help {
|
||||
}
|
||||
|
||||
// listOptions returns a list of options of cfg.
|
||||
func listOptions(cfg interface{}) (opts []Help) {
|
||||
func listOptions(cfg any) (opts []Help) {
|
||||
// resolve indirection if cfg is a pointer
|
||||
v := reflect.Indirect(reflect.ValueOf(cfg))
|
||||
|
||||
@@ -145,7 +145,7 @@ func (o Options) Extract(ns string) Options {
|
||||
|
||||
// Apply sets the options on dst via reflection, using the struct tag `option`.
|
||||
// The namespace argument (ns) is only used for error messages.
|
||||
func (o Options) Apply(ns string, dst interface{}) error {
|
||||
func (o Options) Apply(ns string, dst any) error {
|
||||
v := reflect.ValueOf(dst).Elem()
|
||||
|
||||
fields := make(map[string]reflect.StructField)
|
||||
|
||||
@@ -247,7 +247,7 @@ func TestListOptions(t *testing.T) {
|
||||
}{}
|
||||
|
||||
tests := []struct {
|
||||
cfg interface{}
|
||||
cfg any
|
||||
opts []Help
|
||||
}{
|
||||
{
|
||||
@@ -298,11 +298,11 @@ func TestListOptions(t *testing.T) {
|
||||
|
||||
func TestAppendAllOptions(t *testing.T) {
|
||||
tests := []struct {
|
||||
cfgs map[string]interface{}
|
||||
cfgs map[string]any
|
||||
opts []Help
|
||||
}{
|
||||
{
|
||||
map[string]interface{}{
|
||||
map[string]any{
|
||||
"local": struct {
|
||||
Foo string `option:"foo" help:"bar text help"`
|
||||
}{},
|
||||
|
||||
@@ -291,7 +291,7 @@ func (c *Checker) ReadPacks(ctx context.Context, filter func(packs map[restic.ID
|
||||
// as packs are streamed the concurrency is limited by IO
|
||||
workerCount := int(c.repo.Connections())
|
||||
// run workers
|
||||
for i := 0; i < workerCount; i++ {
|
||||
for range workerCount {
|
||||
g.Go(func() error {
|
||||
bufRd := bufio.NewReaderSize(nil, maxStreamBufferSize)
|
||||
dec, err := zstd.NewReader(nil)
|
||||
|
||||
@@ -145,7 +145,7 @@ func (m *MACKey) UnmarshalJSON(data []byte) error {
|
||||
// Valid tests whether the key k is valid (i.e. not zero).
|
||||
func (m *MACKey) Valid() bool {
|
||||
nonzeroK := false
|
||||
for i := 0; i < len(m.K); i++ {
|
||||
for i := range len(m.K) {
|
||||
if m.K[i] != 0 {
|
||||
nonzeroK = true
|
||||
}
|
||||
@@ -155,7 +155,7 @@ func (m *MACKey) Valid() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
for i := 0; i < len(m.R); i++ {
|
||||
for i := range len(m.R) {
|
||||
if m.R[i] != 0 {
|
||||
return true
|
||||
}
|
||||
@@ -183,7 +183,7 @@ func (k *EncryptionKey) UnmarshalJSON(data []byte) error {
|
||||
|
||||
// Valid tests whether the key k is valid (i.e. not zero).
|
||||
func (k *EncryptionKey) Valid() bool {
|
||||
for i := 0; i < len(k); i++ {
|
||||
for i := range len(k) {
|
||||
if k[i] != 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ func TestNonceValid(t *testing.T) {
|
||||
t.Error("null nonce detected as valid")
|
||||
}
|
||||
|
||||
for i := 0; i < 100; i++ {
|
||||
for range 100 {
|
||||
nonce = NewRandomNonce()
|
||||
if !validNonce(nonce) {
|
||||
t.Errorf("random nonce not detected as valid: %02x", nonce)
|
||||
|
||||
@@ -20,12 +20,12 @@ func TestIndexSerialize(t *testing.T) {
|
||||
idx := index.NewIndex()
|
||||
|
||||
// create 50 packs with 20 blobs each
|
||||
for i := 0; i < 50; i++ {
|
||||
for i := range 50 {
|
||||
packID := restic.NewRandomID()
|
||||
var blobs pack.Blobs
|
||||
|
||||
pos := uint(0)
|
||||
for j := 0; j < 20; j++ {
|
||||
for j := range 20 {
|
||||
length := uint(i*100 + j)
|
||||
uncompressedLength := uint(0)
|
||||
if i >= 25 {
|
||||
@@ -84,12 +84,12 @@ func TestIndexSerialize(t *testing.T) {
|
||||
|
||||
// add more blobs to idx
|
||||
newtests := []*pack.PackedBlob{}
|
||||
for i := 0; i < 10; i++ {
|
||||
for i := range 10 {
|
||||
packID := restic.NewRandomID()
|
||||
var blobs pack.Blobs
|
||||
|
||||
pos := uint(0)
|
||||
for j := 0; j < 10; j++ {
|
||||
for j := range 10 {
|
||||
length := uint(i*100 + j)
|
||||
pb := &pack.PackedBlob{
|
||||
Pack: packID,
|
||||
@@ -144,12 +144,12 @@ func TestIndexSize(t *testing.T) {
|
||||
|
||||
packs := 200
|
||||
blobCount := 100
|
||||
for i := 0; i < packs; i++ {
|
||||
for i := range packs {
|
||||
packID := restic.NewRandomID()
|
||||
var blobs pack.Blobs
|
||||
|
||||
pos := uint(0)
|
||||
for j := 0; j < blobCount; j++ {
|
||||
for j := range blobCount {
|
||||
length := uint(i*100 + j)
|
||||
blobs = append(blobs, pack.Blob{
|
||||
BlobHandle: restic.NewRandomBlobHandle(),
|
||||
@@ -400,7 +400,7 @@ func TestIndexPacks(t *testing.T) {
|
||||
idx := index.NewIndex()
|
||||
packs := restic.NewIDSet()
|
||||
|
||||
for i := 0; i < 20; i++ {
|
||||
for range 20 {
|
||||
packID := restic.NewRandomID()
|
||||
idx.StorePack(packID, pack.Blobs{
|
||||
{
|
||||
@@ -432,7 +432,7 @@ func createRandomIndex(rng *rand.Rand, packfiles int) (idx *index.Index, lookupB
|
||||
idx.Preallocate(restic.DataBlob, packfiles*9)
|
||||
|
||||
// create index with given number of pack files
|
||||
for i := 0; i < packfiles; i++ {
|
||||
for i := range packfiles {
|
||||
packID := NewRandomTestID(rng)
|
||||
var blobs pack.Blobs
|
||||
offset := 0
|
||||
@@ -523,12 +523,12 @@ func TestIndexHas(t *testing.T) {
|
||||
idx := index.NewIndex()
|
||||
|
||||
// create 50 packs with 20 blobs each
|
||||
for i := 0; i < 50; i++ {
|
||||
for i := range 50 {
|
||||
packID := restic.NewRandomID()
|
||||
var blobs pack.Blobs
|
||||
|
||||
pos := uint(0)
|
||||
for j := 0; j < 20; j++ {
|
||||
for j := range 20 {
|
||||
length := uint(i*100 + j)
|
||||
uncompressedLength := uint(0)
|
||||
if i >= 25 {
|
||||
@@ -564,7 +564,7 @@ func TestMixedEachByPack(t *testing.T) {
|
||||
|
||||
expected := make(map[restic.ID]int)
|
||||
// create 50 packs with 2 blobs each
|
||||
for i := 0; i < 50; i++ {
|
||||
for range 50 {
|
||||
packID := restic.NewRandomID()
|
||||
expected[packID] = 1
|
||||
blobs := pack.Blobs{
|
||||
@@ -602,7 +602,7 @@ func TestEachByPackIgnoes(t *testing.T) {
|
||||
ignores := restic.NewIDSet()
|
||||
expected := make(map[restic.ID]int)
|
||||
// create 50 packs with one blob each
|
||||
for i := 0; i < 50; i++ {
|
||||
for i := range 50 {
|
||||
packID := restic.NewRandomID()
|
||||
if i < 3 {
|
||||
ignores.Insert(packID)
|
||||
|
||||
@@ -42,7 +42,7 @@ func TestIndexMapForeach(t *testing.T) {
|
||||
// empty iteration
|
||||
}
|
||||
|
||||
for i := 0; i < N; i++ {
|
||||
for i := range N {
|
||||
var id restic.ID
|
||||
id[0] = byte(i)
|
||||
m.add(id, uint32(i), uint32(i), uint32(i), uint32(i/2))
|
||||
@@ -90,11 +90,11 @@ func TestIndexMapForeachWithID(t *testing.T) {
|
||||
rtest.Equals(t, 0, n)
|
||||
|
||||
// Test insertion and retrieval of duplicates.
|
||||
for i := 0; i < ndups; i++ {
|
||||
for i := range ndups {
|
||||
m.add(id, uint32(i), 0, 0, 0)
|
||||
}
|
||||
|
||||
for i := 0; i < 100; i++ {
|
||||
for range 100 {
|
||||
var otherid restic.ID
|
||||
r.Read(otherid[:])
|
||||
m.add(otherid, math.MaxUint32, 0, 0, 0)
|
||||
@@ -116,13 +116,13 @@ func TestIndexMapForeachWithID(t *testing.T) {
|
||||
func TestHashedArrayTree(t *testing.T) {
|
||||
hat := newHAT()
|
||||
const testSize = 1024
|
||||
for i := uint(0); i < testSize; i++ {
|
||||
for i := range uint(testSize) {
|
||||
rtest.Assert(t, hat.Size() == i, "expected hat size %v got %v", i, hat.Size())
|
||||
e, idx := hat.Alloc()
|
||||
rtest.Assert(t, idx == i, "expected entry at idx %v got %v", i, idx)
|
||||
e.length = uint32(i)
|
||||
}
|
||||
for i := uint(0); i < testSize; i++ {
|
||||
for i := range uint(testSize) {
|
||||
e := hat.Ref(i)
|
||||
rtest.Assert(t, e.length == uint32(i), "expected entry to contain %v got %v", uint32(i), e.length)
|
||||
}
|
||||
|
||||
@@ -452,7 +452,7 @@ func (mi *MasterIndex) Rewrite(ctx context.Context, repo restic.Unpacked[restic.
|
||||
// the index files are probably already cached at this point
|
||||
loaderCount := runtime.GOMAXPROCS(0)
|
||||
// run workers on ch
|
||||
for i := 0; i < loaderCount; i++ {
|
||||
for range loaderCount {
|
||||
rewriteWg.Add(1)
|
||||
wg.Go(loader)
|
||||
}
|
||||
@@ -668,7 +668,7 @@ func (mi *MasterIndex) ListPacks(ctx context.Context, packs restic.IDSet) <-chan
|
||||
go func() {
|
||||
defer close(out)
|
||||
// only resort a part of the index to keep the memory overhead bounded
|
||||
for i := byte(0); i < 16; i++ {
|
||||
for i := range byte(16) {
|
||||
packBlob := make(map[restic.ID]pack.Blobs)
|
||||
for pack := range packs {
|
||||
if pack[0]&0xf == i {
|
||||
|
||||
@@ -416,7 +416,7 @@ var (
|
||||
func createFilledRepo(t testing.TB, snapshots int, version uint) (*repository.Repository, restic.Unpacked[restic.FileType]) {
|
||||
repo, unpacked, _ := repository.TestRepositoryWithVersion(t, version)
|
||||
|
||||
for i := 0; i < snapshots; i++ {
|
||||
for i := range snapshots {
|
||||
data.TestCreateSnapshot(t, repo, snapshotTime.Add(time.Duration(i)*time.Second), depth)
|
||||
}
|
||||
return repo, unpacked
|
||||
@@ -595,11 +595,11 @@ func TestRewriteOversizedIndex(t *testing.T) {
|
||||
// build oversized index
|
||||
idx := index.NewIndex()
|
||||
numPacks := 5
|
||||
for p := 0; p < numPacks; p++ {
|
||||
for range numPacks {
|
||||
packID := restic.NewRandomID()
|
||||
packBlobs := make(pack.Blobs, 0, fullIndexCount)
|
||||
|
||||
for i := 0; i < fullIndexCount; i++ {
|
||||
for i := range fullIndexCount {
|
||||
blob := pack.Blob{
|
||||
BlobHandle: restic.BlobHandle{
|
||||
Type: restic.DataBlob,
|
||||
|
||||
@@ -44,11 +44,11 @@ var lockerInst = &locker{
|
||||
|
||||
// LockRepo acquires a repository lock. The returned context is cancelled when
|
||||
// Unlock is called; cancelling the original context stops lock refresh.
|
||||
func LockRepo(ctx context.Context, repo *Repository, exclusive bool, retryLock time.Duration, printRetry func(msg string), logger func(format string, args ...interface{})) (func(), context.Context, error) {
|
||||
func LockRepo(ctx context.Context, repo *Repository, exclusive bool, retryLock time.Duration, printRetry func(msg string), logger func(format string, args ...any)) (func(), context.Context, error) {
|
||||
return lockerInst.Lock(ctx, repo, exclusive, retryLock, printRetry, logger)
|
||||
}
|
||||
|
||||
func (l *locker) Lock(ctx context.Context, r *Repository, exclusive bool, retryLock time.Duration, printRetry func(msg string), logger func(format string, args ...interface{})) (func(), context.Context, error) {
|
||||
func (l *locker) Lock(ctx context.Context, r *Repository, exclusive bool, retryLock time.Duration, printRetry func(msg string), logger func(format string, args ...any)) (func(), context.Context, error) {
|
||||
var lock *lockHandle
|
||||
var err error
|
||||
|
||||
@@ -121,7 +121,7 @@ type refreshLockRequest struct {
|
||||
result chan bool
|
||||
}
|
||||
|
||||
func (l *locker) refreshLocks(ctx context.Context, backend backend.Backend, unlocker *unlocker, refreshed chan<- struct{}, forceRefresh <-chan refreshLockRequest, logger func(format string, args ...interface{})) {
|
||||
func (l *locker) refreshLocks(ctx context.Context, backend backend.Backend, unlocker *unlocker, refreshed chan<- struct{}, forceRefresh <-chan refreshLockRequest, logger func(format string, args ...any)) {
|
||||
debug.Log("start")
|
||||
lock := unlocker.lock
|
||||
ticker := time.NewTicker(l.refreshInterval)
|
||||
@@ -185,7 +185,7 @@ func (l *locker) refreshLocks(ctx context.Context, backend backend.Backend, unlo
|
||||
}
|
||||
}
|
||||
|
||||
func (l *locker) monitorLockRefresh(ctx context.Context, unlocker *unlocker, refreshed <-chan struct{}, forceRefresh chan<- refreshLockRequest, logger func(format string, args ...interface{})) {
|
||||
func (l *locker) monitorLockRefresh(ctx context.Context, unlocker *unlocker, refreshed <-chan struct{}, forceRefresh chan<- refreshLockRequest, logger func(format string, args ...any)) {
|
||||
// time.Now() might use a monotonic timer which is paused during standby
|
||||
// convert to unix time to ensure we compare real time values
|
||||
lastRefresh := time.Now().UnixNano()
|
||||
@@ -247,7 +247,7 @@ func (l *locker) monitorLockRefresh(ctx context.Context, unlocker *unlocker, ref
|
||||
}
|
||||
}
|
||||
|
||||
func tryRefreshStaleLock(ctx context.Context, be backend.Backend, lock *lockHandle, cancel context.CancelFunc, logger func(format string, args ...interface{})) bool {
|
||||
func tryRefreshStaleLock(ctx context.Context, be backend.Backend, lock *lockHandle, cancel context.CancelFunc, logger func(format string, args ...any)) bool {
|
||||
freeze := backend.AsBackend[backend.FreezeBackend](be)
|
||||
if freeze != nil {
|
||||
debug.Log("freezing backend")
|
||||
|
||||
@@ -164,7 +164,7 @@ func (l *lockHandle) checkForOtherLocks(ctx context.Context) error {
|
||||
}
|
||||
delay := initialWaitBetweenLockRetries
|
||||
// retry locking a few times
|
||||
for i := 0; i < 4; i++ {
|
||||
for i := range 4 {
|
||||
if i != 0 {
|
||||
// sleep between retries to give backend some time to settle
|
||||
if err := cancelableDelay(ctx, delay); err != nil {
|
||||
|
||||
@@ -35,7 +35,7 @@ func openLockTestRepo(t *testing.T, wrapper backendWrapper) (*Repository, backen
|
||||
}
|
||||
|
||||
func checkedLockRepo(ctx context.Context, t *testing.T, repo *Repository, lockerInst *locker, retryLock time.Duration) (func(), context.Context) {
|
||||
unlock, wrappedCtx, err := lockerInst.Lock(ctx, repo, false, retryLock, func(msg string) {}, func(format string, args ...interface{}) {})
|
||||
unlock, wrappedCtx, err := lockerInst.Lock(ctx, repo, false, retryLock, func(msg string) {}, func(format string, args ...any) {})
|
||||
rtest.OK(t, err)
|
||||
rtest.OK(t, wrappedCtx.Err())
|
||||
return unlock, wrappedCtx
|
||||
@@ -73,10 +73,10 @@ func TestLockConflict(t *testing.T) {
|
||||
repo, be := openLockTestRepo(t, nil)
|
||||
repo2 := TestOpenBackend(t, be)
|
||||
|
||||
unlock, _, err := LockRepo(context.Background(), repo, true, 0, func(msg string) {}, func(format string, args ...interface{}) {})
|
||||
unlock, _, err := LockRepo(context.Background(), repo, true, 0, func(msg string) {}, func(format string, args ...any) {})
|
||||
rtest.OK(t, err)
|
||||
defer unlock()
|
||||
_, _, err = LockRepo(context.Background(), repo2, false, 0, func(msg string) {}, func(format string, args ...interface{}) {})
|
||||
_, _, err = LockRepo(context.Background(), repo2, false, 0, func(msg string) {}, func(format string, args ...any) {})
|
||||
if err == nil {
|
||||
t.Fatal("second lock should have failed")
|
||||
}
|
||||
@@ -237,14 +237,14 @@ func TestLockWaitTimeout(t *testing.T) {
|
||||
t.Parallel()
|
||||
repo, _ := openLockTestRepo(t, nil)
|
||||
|
||||
elock, _, err := LockRepo(context.TODO(), repo, true, 0, func(msg string) {}, func(format string, args ...interface{}) {})
|
||||
elock, _, err := LockRepo(context.TODO(), repo, true, 0, func(msg string) {}, func(format string, args ...any) {})
|
||||
rtest.OK(t, err)
|
||||
defer elock()
|
||||
|
||||
retryLock := 200 * time.Millisecond
|
||||
|
||||
start := time.Now()
|
||||
_, _, err = LockRepo(context.TODO(), repo, false, retryLock, func(msg string) {}, func(format string, args ...interface{}) {})
|
||||
_, _, err = LockRepo(context.TODO(), repo, false, retryLock, func(msg string) {}, func(format string, args ...any) {})
|
||||
duration := time.Since(start)
|
||||
|
||||
rtest.Assert(t, err != nil,
|
||||
@@ -259,7 +259,7 @@ func TestLockWaitCancel(t *testing.T) {
|
||||
t.Parallel()
|
||||
repo, _ := openLockTestRepo(t, nil)
|
||||
|
||||
elock, _, err := LockRepo(context.TODO(), repo, true, 0, func(msg string) {}, func(format string, args ...interface{}) {})
|
||||
elock, _, err := LockRepo(context.TODO(), repo, true, 0, func(msg string) {}, func(format string, args ...any) {})
|
||||
rtest.OK(t, err)
|
||||
defer elock()
|
||||
|
||||
@@ -270,7 +270,7 @@ func TestLockWaitCancel(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.TODO())
|
||||
time.AfterFunc(cancelAfter, cancel)
|
||||
|
||||
_, _, err = LockRepo(ctx, repo, false, retryLock, func(msg string) {}, func(format string, args ...interface{}) {})
|
||||
_, _, err = LockRepo(ctx, repo, false, retryLock, func(msg string) {}, func(format string, args ...any) {})
|
||||
duration := time.Since(start)
|
||||
|
||||
rtest.Assert(t, err != nil,
|
||||
@@ -285,7 +285,7 @@ func TestLockWaitSuccess(t *testing.T) {
|
||||
t.Parallel()
|
||||
repo, _ := openLockTestRepo(t, nil)
|
||||
|
||||
elock, _, err := LockRepo(context.TODO(), repo, true, 0, func(msg string) {}, func(format string, args ...interface{}) {})
|
||||
elock, _, err := LockRepo(context.TODO(), repo, true, 0, func(msg string) {}, func(format string, args ...any) {})
|
||||
rtest.OK(t, err)
|
||||
|
||||
retryLock := 200 * time.Millisecond
|
||||
@@ -295,7 +295,7 @@ func TestLockWaitSuccess(t *testing.T) {
|
||||
elock()
|
||||
})
|
||||
|
||||
unlock, _, err := LockRepo(context.TODO(), repo, false, retryLock, func(msg string) {}, func(format string, args ...interface{}) {})
|
||||
unlock, _, err := LockRepo(context.TODO(), repo, false, retryLock, func(msg string) {}, func(format string, args ...any) {})
|
||||
rtest.OK(t, err)
|
||||
unlock()
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ func verifyHeader(k *crypto.Key, header []byte, expected []Blob) error {
|
||||
if len(decoded) != len(expected) {
|
||||
return fmt.Errorf("pack header size mismatch")
|
||||
}
|
||||
for i := 0; i < len(decoded); i++ {
|
||||
for i := range decoded {
|
||||
if decoded[i] != expected[i] {
|
||||
return fmt.Errorf("pack header entry mismatch got %v instead of %v", decoded[i], expected[i])
|
||||
}
|
||||
|
||||
@@ -132,10 +132,7 @@ func TestReadRecords(t *testing.T) {
|
||||
testReadRecords := func(dataSize, entryCount, totalRecords int) {
|
||||
totalHeader := rtest.Random(0, totalRecords*int(entrySize)+crypto.Extension)
|
||||
bufSize := entryCount*int(entrySize) + crypto.Extension
|
||||
off := len(totalHeader) - bufSize
|
||||
if off < 0 {
|
||||
off = 0
|
||||
}
|
||||
off := max(len(totalHeader)-bufSize, 0)
|
||||
expectedHeader := totalHeader[off:]
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
@@ -172,8 +169,8 @@ func TestReadRecords(t *testing.T) {
|
||||
testReadRecords(dataSize+3, 1, 1)
|
||||
testReadRecords(dataSize+4, 1, 1)
|
||||
|
||||
for i := 0; i < 2; i++ {
|
||||
for j := 0; j < 2; j++ {
|
||||
for i := range 2 {
|
||||
for j := range 2 {
|
||||
testReadRecords(dataSize, i, j)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ func randomID(rd io.Reader) restic.ID {
|
||||
const maxBlobSize = 1 << 20
|
||||
|
||||
func fillPacks(t testing.TB, rnd *rand.Rand, pm *packerManager, buf []byte) (bytes int) {
|
||||
for i := 0; i < 102; i++ {
|
||||
for range 102 {
|
||||
l := rnd.Intn(maxBlobSize)
|
||||
id := randomID(rnd)
|
||||
buf = buf[:l]
|
||||
|
||||
@@ -33,7 +33,7 @@ func TestPruneMaxUnusedDuplicate(t *testing.T) {
|
||||
const blobSize = 1024 * 1024
|
||||
|
||||
bufs := [][]byte{}
|
||||
for i := 0; i < 4; i++ {
|
||||
for range 4 {
|
||||
// use uniform length for simpler control via MaxUnusedBytes
|
||||
buf := make([]byte, blobSize)
|
||||
random.Read(buf)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user