mirror of
https://github.com/restic/restic.git
synced 2026-09-20 02:58:30 +00:00
Apply go fix -any ./...
This commit is contained in:
@@ -181,7 +181,7 @@ var ErrNoSourceData = errors.Fatal("all source directories/files do not exist")
|
|||||||
|
|
||||||
// filterExisting returns the items that exist and can be accessed. It returns
|
// filterExisting returns the items that exist and can be accessed. It returns
|
||||||
// ErrNoSourceData if none remain, or ErrInvalidSourceData if some were skipped.
|
// 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 {
|
for _, item := range items {
|
||||||
_, err := fs.Lstat(item)
|
_, err := fs.Lstat(item)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -332,7 +332,7 @@ func (opts BackupOptions) Check(gopts global.Options, args []string) error {
|
|||||||
|
|
||||||
// collectRejectByNameFuncs returns a list of all functions which may reject data
|
// collectRejectByNameFuncs returns a list of all functions which may reject data
|
||||||
// from being saved in a snapshot based on path only
|
// 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
|
// exclude restic cache
|
||||||
if repo.Cache() != nil {
|
if repo.Cache() != nil {
|
||||||
f, err := rejectResticCache(repo)
|
f, err := rejectResticCache(repo)
|
||||||
@@ -356,7 +356,7 @@ func collectRejectByNameFuncs(opts BackupOptions, repo *repository.Repository, w
|
|||||||
|
|
||||||
// collectRejectFuncs returns a list of all functions which may reject data
|
// collectRejectFuncs returns a list of all functions which may reject data
|
||||||
// from being saved in a snapshot based on path and file info
|
// 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
|
// allowed devices
|
||||||
if opts.ExcludeOtherFS && !opts.Stdin && !opts.StdinCommand {
|
if opts.ExcludeOtherFS && !opts.Stdin && !opts.StdinCommand {
|
||||||
f, err := archiver.RejectByDevice(targets, fs)
|
f, err := archiver.RejectByDevice(targets, fs)
|
||||||
@@ -404,7 +404,7 @@ func collectRejectFuncs(opts BackupOptions, targets []string, fs fs.FS, warnf fu
|
|||||||
}
|
}
|
||||||
|
|
||||||
// collectTargets returns a list of target files/dirs from several sources.
|
// 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 {
|
if opts.Stdin || opts.StdinCommand {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@@ -589,7 +589,7 @@ func runBackup(ctx context.Context, opts BackupOptions, gopts global.Options, te
|
|||||||
_ = progressReporter.Error(item, err)
|
_ = progressReporter.Error(item, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
messageHandler := func(msg string, args ...interface{}) {
|
messageHandler := func(msg string, args ...any) {
|
||||||
if !gopts.JSON {
|
if !gopts.JSON {
|
||||||
printer.P(msg, args...)
|
printer.P(msg, args...)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -570,15 +570,15 @@ func (*jsonErrorPrinter) NewCounterTerminalOnly(_ string) restic.Counter {
|
|||||||
return restic.NoopCounter
|
return restic.NoopCounter
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *jsonErrorPrinter) E(msg string, args ...interface{}) {
|
func (p *jsonErrorPrinter) E(msg string, args ...any) {
|
||||||
status := checkError{
|
status := checkError{
|
||||||
MessageType: "error",
|
MessageType: "error",
|
||||||
Message: fmt.Sprintf(msg, args...),
|
Message: fmt.Sprintf(msg, args...),
|
||||||
}
|
}
|
||||||
p.term.Error(ui.ToJSONString(status))
|
p.term.Error(ui.ToJSONString(status))
|
||||||
}
|
}
|
||||||
func (*jsonErrorPrinter) S(_ string, _ ...interface{}) {}
|
func (*jsonErrorPrinter) S(_ string, _ ...any) {}
|
||||||
func (*jsonErrorPrinter) P(_ string, _ ...interface{}) {}
|
func (*jsonErrorPrinter) P(_ string, _ ...any) {}
|
||||||
func (*jsonErrorPrinter) PT(_ string, _ ...interface{}) {}
|
func (*jsonErrorPrinter) PT(_ string, _ ...any) {}
|
||||||
func (*jsonErrorPrinter) V(_ string, _ ...interface{}) {}
|
func (*jsonErrorPrinter) V(_ string, _ ...any) {}
|
||||||
func (*jsonErrorPrinter) VV(_ string, _ ...interface{}) {}
|
func (*jsonErrorPrinter) VV(_ string, _ ...any) {}
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ type Comparer struct {
|
|||||||
repo restic.BlobLoader
|
repo restic.BlobLoader
|
||||||
opts DiffOptions
|
opts DiffOptions
|
||||||
printChange func(change *Change)
|
printChange func(change *Change)
|
||||||
printError func(string, ...interface{})
|
printError func(string, ...any)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Change struct {
|
type Change struct {
|
||||||
@@ -158,7 +158,7 @@ type DiffStatsContainer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// updateBlobs updates the blob counters in the stats 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() {
|
for h := range blobs.Keys() {
|
||||||
switch h.Type {
|
switch h.Type {
|
||||||
case restic.DataBlob:
|
case restic.DataBlob:
|
||||||
|
|||||||
@@ -136,9 +136,9 @@ type statefulOutput struct {
|
|||||||
oldsn *data.Snapshot
|
oldsn *data.Snapshot
|
||||||
hits int
|
hits int
|
||||||
printer interface {
|
printer interface {
|
||||||
S(string, ...interface{})
|
S(string, ...any)
|
||||||
P(string, ...interface{})
|
P(string, ...any)
|
||||||
E(string, ...interface{})
|
E(string, ...any)
|
||||||
}
|
}
|
||||||
stdout io.Writer
|
stdout io.Writer
|
||||||
}
|
}
|
||||||
@@ -281,9 +281,9 @@ type Finder struct {
|
|||||||
treeIDs map[string]struct{}
|
treeIDs map[string]struct{}
|
||||||
itemsFound int
|
itemsFound int
|
||||||
printer interface {
|
printer interface {
|
||||||
S(string, ...interface{})
|
S(string, ...any)
|
||||||
P(string, ...interface{})
|
P(string, ...any)
|
||||||
E(string, ...interface{})
|
E(string, ...any)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -290,8 +290,8 @@ type textLsPrinter struct {
|
|||||||
ListLong bool
|
ListLong bool
|
||||||
HumanReadable bool
|
HumanReadable bool
|
||||||
termPrinter interface {
|
termPrinter interface {
|
||||||
P(msg string, args ...interface{})
|
P(msg string, args ...any)
|
||||||
S(msg string, args ...interface{})
|
S(msg string, args ...any)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ func TestLsNodeJSON(t *testing.T) {
|
|||||||
rtest.Equals(t, expect+"\n", buf.String())
|
rtest.Equals(t, expect+"\n", buf.String())
|
||||||
|
|
||||||
// Sanity check: output must be valid JSON.
|
// Sanity check: output must be valid JSON.
|
||||||
var v interface{}
|
var v any
|
||||||
err = json.NewDecoder(buf).Decode(&v)
|
err = json.NewDecoder(buf).Decode(&v)
|
||||||
rtest.OK(t, err)
|
rtest.OK(t, err)
|
||||||
}
|
}
|
||||||
@@ -121,7 +121,7 @@ func TestLsNcduNode(t *testing.T) {
|
|||||||
rtest.Equals(t, expect, string(out))
|
rtest.Equals(t, expect, string(out))
|
||||||
|
|
||||||
// Sanity check: output must be valid JSON.
|
// Sanity check: output must be valid JSON.
|
||||||
var v interface{}
|
var v any
|
||||||
err = json.Unmarshal(out, &v)
|
err = json.Unmarshal(out, &v)
|
||||||
rtest.OK(t, err)
|
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)
|
debug.Log("fuse: %v", msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ func init() {
|
|||||||
pflag.Parse()
|
pflag.Parse()
|
||||||
}
|
}
|
||||||
|
|
||||||
func die(f string, args ...interface{}) {
|
func die(f string, args ...any) {
|
||||||
if !strings.HasSuffix(f, "\n") {
|
if !strings.HasSuffix(f, "\n") {
|
||||||
f += "\n"
|
f += "\n"
|
||||||
}
|
}
|
||||||
@@ -48,7 +48,7 @@ func die(f string, args ...interface{}) {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func msg(f string, args ...interface{}) {
|
func msg(f string, args ...any) {
|
||||||
if !strings.HasSuffix(f, "\n") {
|
if !strings.HasSuffix(f, "\n") {
|
||||||
f += "\n"
|
f += "\n"
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,7 @@ func msg(f string, args ...interface{}) {
|
|||||||
fmt.Printf(f, args...)
|
fmt.Printf(f, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func verbose(f string, args ...interface{}) {
|
func verbose(f string, args ...any) {
|
||||||
if !opts.Verbose {
|
if !opts.Verbose {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ func init() {
|
|||||||
pflag.Parse()
|
pflag.Parse()
|
||||||
}
|
}
|
||||||
|
|
||||||
func die(f string, args ...interface{}) {
|
func die(f string, args ...any) {
|
||||||
if !strings.HasSuffix(f, "\n") {
|
if !strings.HasSuffix(f, "\n") {
|
||||||
f += "\n"
|
f += "\n"
|
||||||
}
|
}
|
||||||
@@ -52,7 +52,7 @@ func die(f string, args ...interface{}) {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func msg(f string, args ...interface{}) {
|
func msg(f string, args ...any) {
|
||||||
if !strings.HasSuffix(f, "\n") {
|
if !strings.HasSuffix(f, "\n") {
|
||||||
f += "\n"
|
f += "\n"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1982,7 +1982,7 @@ func TestArchiverParent(t *testing.T) {
|
|||||||
t.Logf("testfs: %v", testFS)
|
t.Logf("testfs: %v", testFS)
|
||||||
|
|
||||||
// check that all files have been read exactly once
|
// 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)
|
file, ok := item.(TestFile)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -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 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
|
// non-nil, it is going to be used in the RejectByNameFunc to expedite the evaluation
|
||||||
// of a directory based on previous visits.
|
// 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 == "" {
|
if excludeFileSpec == "" {
|
||||||
return nil, errors.New("name for exclusion tagfile is empty")
|
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
|
// 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
|
// header. If rc is non-nil, it is used to expedite the evaluation of a
|
||||||
// directory based on previous visits.
|
// 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 == "" {
|
if tagFilename == "" {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -136,7 +136,7 @@ func isExcludedByFile(filename, tagFilename, header string, rc *rejectionCache,
|
|||||||
return rejected
|
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)
|
tf := fsInst.Join(dir, tagFilename)
|
||||||
_, err := fsInst.Lstat(tf)
|
_, err := fsInst.Lstat(tf)
|
||||||
if errors.Is(err, os.ErrNotExist) {
|
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
|
// 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 {
|
return func(item string, fi *fs.ExtendedFileInfo, _ fs.FS) bool {
|
||||||
recall, err := fi.RecallOnDataAccess()
|
recall, err := fi.RecallOnDataAccess()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ func TestIsExcludedByFile(t *testing.T) {
|
|||||||
if tc.content == "" {
|
if tc.content == "" {
|
||||||
h = ""
|
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)
|
t.Fatalf("expected %v, got %v", tc.want, got)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -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.
|
// 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 {
|
func (d TestDir) String() string {
|
||||||
return "<Dir>"
|
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
|
// TestWalkFunc is used by TestWalkFiles to traverse the dir. When an error is
|
||||||
// returned, traversal stops and the surrounding test is marked as failed.
|
// 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
|
// TestWalkFiles runs fn for each file/directory in dir, the filename will be
|
||||||
// constructed with target as the prefix. Symlinks on Windows are ignored.
|
// 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{})
|
pathsChecked := make(map[string]struct{})
|
||||||
|
|
||||||
// first, test that all items are there
|
// 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)
|
fi, err := os.Lstat(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -28,30 +28,30 @@ func (t *MockT) Fail() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fatal is equivalent to Log followed by FailNow.
|
// 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.T.Logf("MockT Fatal called with %v", args)
|
||||||
t.HasFailed = true
|
t.HasFailed = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fatalf is equivalent to Logf followed by FailNow.
|
// 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.T.Logf("MockT Fatal called: "+msg, args...)
|
||||||
t.HasFailed = true
|
t.HasFailed = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error is equivalent to Log followed by Fail.
|
// 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.T.Logf("MockT Error called with %v", args)
|
||||||
t.HasFailed = true
|
t.HasFailed = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Errorf is equivalent to Logf followed by Fail.
|
// 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.T.Logf("MockT Error called: "+msg, args...)
|
||||||
t.HasFailed = true
|
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 {
|
for name, item := range files {
|
||||||
target := filepath.Join(targetdir, filepath.FromSlash(name))
|
target := filepath.Join(targetdir, filepath.FromSlash(name))
|
||||||
err := os.MkdirAll(filepath.Dir(target), 0700)
|
err := os.MkdirAll(filepath.Dir(target), 0700)
|
||||||
@@ -77,7 +77,7 @@ func createFilesAt(t testing.TB, targetdir string, files map[string]interface{})
|
|||||||
func TestTestCreateFiles(t *testing.T) {
|
func TestTestCreateFiles(t *testing.T) {
|
||||||
var tests = []struct {
|
var tests = []struct {
|
||||||
dir TestDir
|
dir TestDir
|
||||||
files map[string]interface{}
|
files map[string]any
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
dir: TestDir{
|
dir: TestDir{
|
||||||
@@ -91,7 +91,7 @@ func TestTestCreateFiles(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
files: map[string]interface{}{
|
files: map[string]any{
|
||||||
"foo": TestFile{Content: "foo"},
|
"foo": TestFile{Content: "foo"},
|
||||||
"subdir": TestDir{},
|
"subdir": TestDir{},
|
||||||
"subdir/subfile": TestFile{Content: "bar"},
|
"subdir/subfile": TestFile{Content: "bar"},
|
||||||
@@ -196,7 +196,7 @@ func TestTestWalkFiles(t *testing.T) {
|
|||||||
got := make(map[string]string)
|
got := make(map[string]string)
|
||||||
|
|
||||||
TestCreateFiles(t, tempdir, test.dir)
|
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)
|
p, err := filepath.Rel(tempdir, path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -216,11 +216,11 @@ func TestTestWalkFiles(t *testing.T) {
|
|||||||
func TestTestEnsureFiles(t *testing.T) {
|
func TestTestEnsureFiles(t *testing.T) {
|
||||||
var tests = []struct {
|
var tests = []struct {
|
||||||
expectFailure bool
|
expectFailure bool
|
||||||
files map[string]interface{}
|
files map[string]any
|
||||||
want TestDir
|
want TestDir
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
files: map[string]interface{}{
|
files: map[string]any{
|
||||||
"foo": TestFile{Content: "foo"},
|
"foo": TestFile{Content: "foo"},
|
||||||
"subdir/subfile": TestFile{Content: "bar"},
|
"subdir/subfile": TestFile{Content: "bar"},
|
||||||
"x/y/link": TestSymlink{Target: filepath.Clean("../../foo")},
|
"x/y/link": TestSymlink{Target: filepath.Clean("../../foo")},
|
||||||
@@ -239,7 +239,7 @@ func TestTestEnsureFiles(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
expectFailure: true,
|
expectFailure: true,
|
||||||
files: map[string]interface{}{
|
files: map[string]any{
|
||||||
"foo": TestFile{Content: "foo"},
|
"foo": TestFile{Content: "foo"},
|
||||||
},
|
},
|
||||||
want: TestDir{
|
want: TestDir{
|
||||||
@@ -251,7 +251,7 @@ func TestTestEnsureFiles(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
expectFailure: true,
|
expectFailure: true,
|
||||||
files: map[string]interface{}{
|
files: map[string]any{
|
||||||
"foo": TestFile{Content: "foo"},
|
"foo": TestFile{Content: "foo"},
|
||||||
"subdir/subfile": TestFile{Content: "bar"},
|
"subdir/subfile": TestFile{Content: "bar"},
|
||||||
},
|
},
|
||||||
@@ -261,7 +261,7 @@ func TestTestEnsureFiles(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
expectFailure: true,
|
expectFailure: true,
|
||||||
files: map[string]interface{}{
|
files: map[string]any{
|
||||||
"foo": TestFile{Content: "xxx"},
|
"foo": TestFile{Content: "xxx"},
|
||||||
},
|
},
|
||||||
want: TestDir{
|
want: TestDir{
|
||||||
@@ -270,7 +270,7 @@ func TestTestEnsureFiles(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
expectFailure: true,
|
expectFailure: true,
|
||||||
files: map[string]interface{}{
|
files: map[string]any{
|
||||||
"foo": TestSymlink{Target: "/xxx"},
|
"foo": TestSymlink{Target: "/xxx"},
|
||||||
},
|
},
|
||||||
want: TestDir{
|
want: TestDir{
|
||||||
@@ -279,7 +279,7 @@ func TestTestEnsureFiles(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
expectFailure: true,
|
expectFailure: true,
|
||||||
files: map[string]interface{}{
|
files: map[string]any{
|
||||||
"foo": TestFile{Content: "foo"},
|
"foo": TestFile{Content: "foo"},
|
||||||
},
|
},
|
||||||
want: TestDir{
|
want: TestDir{
|
||||||
@@ -288,7 +288,7 @@ func TestTestEnsureFiles(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
expectFailure: true,
|
expectFailure: true,
|
||||||
files: map[string]interface{}{
|
files: map[string]any{
|
||||||
"foo": TestSymlink{Target: "xxx"},
|
"foo": TestSymlink{Target: "xxx"},
|
||||||
},
|
},
|
||||||
want: TestDir{
|
want: TestDir{
|
||||||
@@ -297,7 +297,7 @@ func TestTestEnsureFiles(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
expectFailure: true,
|
expectFailure: true,
|
||||||
files: map[string]interface{}{
|
files: map[string]any{
|
||||||
"foo": TestDir{
|
"foo": TestDir{
|
||||||
"foo": TestFile{Content: "foo"},
|
"foo": TestFile{Content: "foo"},
|
||||||
},
|
},
|
||||||
@@ -308,7 +308,7 @@ func TestTestEnsureFiles(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
expectFailure: true,
|
expectFailure: true,
|
||||||
files: map[string]interface{}{
|
files: map[string]any{
|
||||||
"foo": TestFile{Content: "foo"},
|
"foo": TestFile{Content: "foo"},
|
||||||
},
|
},
|
||||||
want: TestDir{
|
want: TestDir{
|
||||||
@@ -341,11 +341,11 @@ func TestTestEnsureFiles(t *testing.T) {
|
|||||||
func TestTestEnsureSnapshot(t *testing.T) {
|
func TestTestEnsureSnapshot(t *testing.T) {
|
||||||
var tests = []struct {
|
var tests = []struct {
|
||||||
expectFailure bool
|
expectFailure bool
|
||||||
files map[string]interface{}
|
files map[string]any
|
||||||
want TestDir
|
want TestDir
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
files: map[string]interface{}{
|
files: map[string]any{
|
||||||
"foo": TestFile{Content: "foo"},
|
"foo": TestFile{Content: "foo"},
|
||||||
filepath.FromSlash("subdir/subfile"): TestFile{Content: "bar"},
|
filepath.FromSlash("subdir/subfile"): TestFile{Content: "bar"},
|
||||||
filepath.FromSlash("x/y/link"): TestSymlink{Target: filepath.FromSlash("../../foo")},
|
filepath.FromSlash("x/y/link"): TestSymlink{Target: filepath.FromSlash("../../foo")},
|
||||||
@@ -366,7 +366,7 @@ func TestTestEnsureSnapshot(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
expectFailure: true,
|
expectFailure: true,
|
||||||
files: map[string]interface{}{
|
files: map[string]any{
|
||||||
"foo": TestFile{Content: "foo"},
|
"foo": TestFile{Content: "foo"},
|
||||||
},
|
},
|
||||||
want: TestDir{
|
want: TestDir{
|
||||||
@@ -377,7 +377,7 @@ func TestTestEnsureSnapshot(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
expectFailure: true,
|
expectFailure: true,
|
||||||
files: map[string]interface{}{
|
files: map[string]any{
|
||||||
"foo": TestFile{Content: "foo"},
|
"foo": TestFile{Content: "foo"},
|
||||||
"bar": TestFile{Content: "bar"},
|
"bar": TestFile{Content: "bar"},
|
||||||
},
|
},
|
||||||
@@ -389,7 +389,7 @@ func TestTestEnsureSnapshot(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
expectFailure: true,
|
expectFailure: true,
|
||||||
files: map[string]interface{}{
|
files: map[string]any{
|
||||||
"foo": TestFile{Content: "foo"},
|
"foo": TestFile{Content: "foo"},
|
||||||
},
|
},
|
||||||
want: TestDir{
|
want: TestDir{
|
||||||
@@ -401,7 +401,7 @@ func TestTestEnsureSnapshot(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
expectFailure: true,
|
expectFailure: true,
|
||||||
files: map[string]interface{}{
|
files: map[string]any{
|
||||||
"foo": TestFile{Content: "foo"},
|
"foo": TestFile{Content: "foo"},
|
||||||
},
|
},
|
||||||
want: TestDir{
|
want: TestDir{
|
||||||
@@ -414,7 +414,7 @@ func TestTestEnsureSnapshot(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
expectFailure: true,
|
expectFailure: true,
|
||||||
files: map[string]interface{}{
|
files: map[string]any{
|
||||||
"foo": TestSymlink{Target: filepath.FromSlash("x/y/z")},
|
"foo": TestSymlink{Target: filepath.FromSlash("x/y/z")},
|
||||||
},
|
},
|
||||||
want: TestDir{
|
want: TestDir{
|
||||||
@@ -425,7 +425,7 @@ func TestTestEnsureSnapshot(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
expectFailure: true,
|
expectFailure: true,
|
||||||
files: map[string]interface{}{
|
files: map[string]any{
|
||||||
"foo": TestSymlink{Target: filepath.FromSlash("x/y/z")},
|
"foo": TestSymlink{Target: filepath.FromSlash("x/y/z")},
|
||||||
},
|
},
|
||||||
want: TestDir{
|
want: TestDir{
|
||||||
@@ -436,7 +436,7 @@ func TestTestEnsureSnapshot(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
expectFailure: true,
|
expectFailure: true,
|
||||||
files: map[string]interface{}{
|
files: map[string]any{
|
||||||
"foo": TestFile{Content: "foo"},
|
"foo": TestFile{Content: "foo"},
|
||||||
},
|
},
|
||||||
want: TestDir{
|
want: TestDir{
|
||||||
|
|||||||
@@ -158,13 +158,13 @@ func supportedAccessTiers() []blob.AccessTier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Open opens the Azure backend at specified container.
|
// 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)
|
return open(cfg, rt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create opens the Azure backend at specified container and creates the container if
|
// Create opens the Azure backend at specified container and creates the container if
|
||||||
// it does not exist yet.
|
// 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)
|
be, err := open(cfg, rt)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ func newClient(ctx context.Context, cfg Config, rt http.RoundTripper) (*b2.Clien
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Open opens a connection to the B2 service.
|
// 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)
|
debug.Log("cfg %#v", cfg)
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
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,
|
// Create opens a connection to the B2 service. If the bucket does not exist yet,
|
||||||
// it is created.
|
// 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)
|
debug.Log("cfg %#v", cfg)
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
|
|||||||
Vendored
+2
-2
@@ -19,13 +19,13 @@ type cacheBackend struct {
|
|||||||
// is finished.
|
// is finished.
|
||||||
inProgressMutex sync.Mutex
|
inProgressMutex sync.Mutex
|
||||||
inProgress map[backend.Handle]chan struct{}
|
inProgress map[backend.Handle]chan struct{}
|
||||||
errorLog func(string, ...interface{})
|
errorLog func(string, ...any)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure Backend implements backend.Backend
|
// ensure Backend implements backend.Backend
|
||||||
var _ backend.Backend = &cacheBackend{}
|
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{
|
return &cacheBackend{
|
||||||
Backend: be,
|
Backend: be,
|
||||||
Cache: c,
|
Cache: c,
|
||||||
|
|||||||
Vendored
+1
-1
@@ -236,7 +236,7 @@ func IsOld(t time.Time, maxAge time.Duration) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Wrap returns a backend with a cache.
|
// 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)
|
return newBackend(be, c, errorLog)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ func open(cfg Config, rt http.RoundTripper) (*gs, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Open opens the gs backend at the specified bucket.
|
// 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)
|
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
|
// The service account must have the "storage.buckets.create" permission to
|
||||||
// create a bucket the does not yet exist.
|
// 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)
|
be, err := open(cfg, rt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ import (
|
|||||||
"github.com/restic/restic/internal/backend"
|
"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) {
|
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, ...interface{})) (backend.Backend, error) {
|
return func(ctx context.Context, cfg C, lim Limiter, errorLog func(string, ...any)) (backend.Backend, error) {
|
||||||
var be backend.Backend
|
var be backend.Backend
|
||||||
be, err := constructor(ctx, cfg, errorLog)
|
be, err := constructor(ctx, cfg, errorLog)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -52,14 +52,14 @@ func open(cfg Config) (*Local, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Open opens the local backend as specified by config.
|
// 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)
|
debug.Log("open local backend at %v", cfg.Path)
|
||||||
return open(cfg)
|
return open(cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create creates all the necessary files and directories for a new local
|
// Create creates all the necessary files and directories for a new local
|
||||||
// backend at dir. Afterwards a new config blob should be created.
|
// 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)
|
debug.Log("create local backend at %v", cfg.Path)
|
||||||
|
|
||||||
be, err := open(cfg)
|
be, err := open(cfg)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
// access and (possibly) credentials needed for access.
|
// access and (possibly) credentials needed for access.
|
||||||
type Location struct {
|
type Location struct {
|
||||||
Scheme string
|
Scheme string
|
||||||
Config interface{}
|
Config any
|
||||||
}
|
}
|
||||||
|
|
||||||
// NoPassword returns the repository location unchanged (there's no sensitive information there)
|
// 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 {
|
type Factory interface {
|
||||||
Scheme() string
|
Scheme() string
|
||||||
ParseConfig(s string) (interface{}, error)
|
ParseConfig(s string) (any, error)
|
||||||
StripPassword(s string) string
|
StripPassword(s string) string
|
||||||
Create(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 interface{}, rt http.RoundTripper, lim limiter.Limiter, errorLog func(string, ...interface{})) (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 {
|
type genericBackendFactory[C any, T backend.Backend] struct {
|
||||||
scheme string
|
scheme string
|
||||||
parseConfigFn func(s string) (*C, error)
|
parseConfigFn func(s string) (*C, error)
|
||||||
stripPasswordFn func(s string) string
|
stripPasswordFn func(s string) string
|
||||||
createFn 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, ...interface{})) (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 {
|
func (f *genericBackendFactory[C, T]) Scheme() string {
|
||||||
return f.scheme
|
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)
|
return f.parseConfigFn(s)
|
||||||
}
|
}
|
||||||
func (f *genericBackendFactory[C, T]) StripPassword(s string) string {
|
func (f *genericBackendFactory[C, T]) StripPassword(s string) string {
|
||||||
@@ -58,10 +58,10 @@ func (f *genericBackendFactory[C, T]) StripPassword(s string) string {
|
|||||||
}
|
}
|
||||||
return s
|
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)
|
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)
|
return f.openFn(ctx, *cfg.(*C), rt, lim, errorLog)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,17 +69,17 @@ func NewHTTPBackendFactory[C any, T backend.Backend](
|
|||||||
scheme string,
|
scheme string,
|
||||||
parseConfigFn func(s string) (*C, error),
|
parseConfigFn func(s string) (*C, error),
|
||||||
stripPasswordFn func(s string) string,
|
stripPasswordFn func(s string) string,
|
||||||
createFn func(ctx context.Context, cfg C, rt http.RoundTripper, errorLog func(string, ...interface{})) (T, error),
|
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, ...interface{})) (T, error)) Factory {
|
openFn func(ctx context.Context, cfg C, rt http.RoundTripper, errorLog func(string, ...any)) (T, error)) Factory {
|
||||||
|
|
||||||
return &genericBackendFactory[C, T]{
|
return &genericBackendFactory[C, T]{
|
||||||
scheme: scheme,
|
scheme: scheme,
|
||||||
parseConfigFn: parseConfigFn,
|
parseConfigFn: parseConfigFn,
|
||||||
stripPasswordFn: stripPasswordFn,
|
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)
|
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)
|
return openFn(ctx, cfg, rt, errorLog)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -89,17 +89,17 @@ func NewLimitedBackendFactory[C any, T backend.Backend](
|
|||||||
scheme string,
|
scheme string,
|
||||||
parseConfigFn func(s string) (*C, error),
|
parseConfigFn func(s string) (*C, error),
|
||||||
stripPasswordFn func(s string) string,
|
stripPasswordFn func(s string) string,
|
||||||
createFn func(ctx context.Context, cfg C, lim limiter.Limiter, errorLog func(string, ...interface{})) (T, error),
|
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, ...interface{})) (T, error)) Factory {
|
openFn func(ctx context.Context, cfg C, lim limiter.Limiter, errorLog func(string, ...any)) (T, error)) Factory {
|
||||||
|
|
||||||
return &genericBackendFactory[C, T]{
|
return &genericBackendFactory[C, T]{
|
||||||
scheme: scheme,
|
scheme: scheme,
|
||||||
parseConfigFn: parseConfigFn,
|
parseConfigFn: parseConfigFn,
|
||||||
stripPasswordFn: stripPasswordFn,
|
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)
|
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)
|
return openFn(ctx, cfg, lim, errorLog)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,10 +33,10 @@ func NewFactory() location.Factory {
|
|||||||
return &struct{}{}, nil
|
return &struct{}{}, nil
|
||||||
},
|
},
|
||||||
location.NoPassword,
|
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
|
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
|
return be, nil
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ func NewFactory() location.Factory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// run starts command with args and initializes the StdioConn.
|
// 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...)
|
cmd := exec.Command(command, args...)
|
||||||
|
|
||||||
p, err := cmd.StderrPipe()
|
p, err := cmd.StderrPipe()
|
||||||
@@ -141,7 +141,7 @@ func wrapConn(c *StdioConn, lim limiter.Limiter) *wrappedConn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New initializes a Backend and starts the process.
|
// 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 (
|
var (
|
||||||
args []string
|
args []string
|
||||||
err error
|
err error
|
||||||
@@ -270,7 +270,7 @@ func newBackend(ctx context.Context, cfg Config, lim limiter.Limiter, errorLog f
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Open starts an rclone process with the given config.
|
// 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)
|
be, err := newBackend(ctx, cfg, lim, errorLog)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -297,7 +297,7 @@ func Open(ctx context.Context, cfg Config, lim limiter.Limiter, errorLog func(st
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create initializes a new restic repo with rclone.
|
// 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)
|
be, err := newBackend(ctx, cfg, lim, errorLog)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Open opens the REST backend with the given config.
|
// 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
|
// use url without trailing slash for layout
|
||||||
url := cfg.URL.String()
|
url := cfg.URL.String()
|
||||||
if url[len(url)-1] == '/' {
|
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.
|
// 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)
|
be, err := Open(ctx, cfg, rt, errorLog)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -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
|
// Open opens the S3 backend at bucket and region. The bucket is created if it
|
||||||
// does not exist yet.
|
// 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)
|
return open(cfg, rt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create opens the S3 backend at bucket and region and creates the bucket if
|
// Create opens the S3 backend at bucket and region and creates the bucket if
|
||||||
// it does not exist yet.
|
// 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)
|
be, err := open(cfg, rt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "open")
|
return nil, errors.Wrap(err, "open")
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ func newMinioTestSuite(t testing.TB) (*test.Suite[s3.Config], func()) {
|
|||||||
return &cfg, nil
|
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) {
|
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 := 0; i < 50; i++ {
|
for i := 0; i < 50; i++ {
|
||||||
be, err = s3.Create(ctx, cfg, rt, errorLog)
|
be, err = s3.Create(ctx, cfg, rt, errorLog)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ func NewFactory() location.Factory {
|
|||||||
return location.NewLimitedBackendFactory("sftp", ParseConfig, location.NoPassword, limiter.WrapBackendConstructor(Create), limiter.WrapBackendConstructor(Open))
|
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)
|
program, args, err := buildSSHCommand(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -147,7 +147,7 @@ func (r *SFTP) clientError() error {
|
|||||||
|
|
||||||
// Open opens an sftp backend as described by the config by running
|
// Open opens an sftp backend as described by the config by running
|
||||||
// "ssh" with the appropriate arguments (or cfg.Command, if set).
|
// "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)
|
debug.Log("open backend with config %#v", cfg)
|
||||||
|
|
||||||
sftp, err := startClient(cfg, errorLog)
|
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"
|
// Create creates an sftp backend as described by the config by running "ssh"
|
||||||
// with the appropriate arguments (or cfg.Command, if set).
|
// 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)
|
sftp, err := startClient(cfg, errorLog)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
debug.Log("unable to start program: %v", err)
|
debug.Log("unable to start program: %v", err)
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ func TestCreateSetsDirPermissions(t *testing.T) {
|
|||||||
|
|
||||||
cfg := testConfig(filepath.Join(rtest.TempDir(t), "repo"))
|
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)
|
rtest.OK(t, err)
|
||||||
defer func() { rtest.OK(t, be.Close()) }()
|
defer func() { rtest.OK(t, be.Close()) }()
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@ func TestSaveSetsDirPermissions(t *testing.T) {
|
|||||||
|
|
||||||
cfg := testConfig(filepath.Join(rtest.TempDir(t), "repo"))
|
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)
|
rtest.OK(t, err)
|
||||||
defer func() { rtest.OK(t, be.Close()) }()
|
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
|
// Open opens the swift backend at a container in region. The container is
|
||||||
// created if it does not exist yet.
|
// 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)
|
debug.Log("config %#v", cfg)
|
||||||
|
|
||||||
be := &beSwift{
|
be := &beSwift{
|
||||||
@@ -202,7 +202,7 @@ func (be *beSwift) List(ctx context.Context, t backend.FileType, fn func(backend
|
|||||||
prefix += "/"
|
prefix += "/"
|
||||||
|
|
||||||
err := be.conn.ObjectsWalk(ctx, be.container, &swift.ObjectsOpts{Prefix: 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)
|
newObjects, err := be.conn.Objects(ctx, be.container, opts)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -192,7 +192,7 @@ func (s *Suite[C]) open(t testing.TB) backend.Backend {
|
|||||||
t.Fatalf("cannot create transport for tests: %v", err)
|
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 {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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).
|
// 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 {
|
if !opts.isEnabled {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,
|
// 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.
|
// 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.
|
// Is reports whether any error in err's tree matches target.
|
||||||
func Is(x, y error) bool { return stderrors.Is(x, y) }
|
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.
|
// 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.
|
// Use the last error found.
|
||||||
var underlyingErr error
|
var underlyingErr error
|
||||||
for i := len(data) - 1; i >= 0; i-- {
|
for i := len(data) - 1; i >= 0; i-- {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ type RejectByNameFunc func(path string) bool
|
|||||||
|
|
||||||
// RejectByPattern returns a RejectByNameFunc which rejects files that match
|
// RejectByPattern returns a RejectByNameFunc which rejects files that match
|
||||||
// one of the patterns.
|
// 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)
|
parsedPatterns := ParsePatterns(patterns)
|
||||||
return func(item string) bool {
|
return func(item string) bool {
|
||||||
matched, err := List(parsedPatterns, item)
|
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.
|
// 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))
|
lowerPatterns := make([]string, len(patterns))
|
||||||
for index, path := range patterns {
|
for index, path := range patterns {
|
||||||
lowerPatterns[index] = strings.ToLower(path)
|
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
|
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
|
var fs []RejectByNameFunc
|
||||||
// add patterns from file
|
// add patterns from file
|
||||||
if len(opts.ExcludeFiles) > 0 {
|
if len(opts.ExcludeFiles) > 0 {
|
||||||
|
|||||||
@@ -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
|
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
|
var fs []IncludeByNameFunc
|
||||||
if len(opts.IncludeFiles) > 0 {
|
if len(opts.IncludeFiles) > 0 {
|
||||||
includePatterns, err := readPatternsFromFiles(opts.IncludeFiles)
|
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
|
// IncludeByPattern returns an IncludeByNameFunc which includes files that match
|
||||||
// one of the patterns.
|
// 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)
|
parsedPatterns := ParsePatterns(patterns)
|
||||||
return func(item string) (matched bool, childMayMatch bool) {
|
return func(item string) (matched bool, childMayMatch bool) {
|
||||||
matched, childMayMatch, err := ListWithChild(parsedPatterns, item)
|
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
|
// IncludeByInsensitivePattern returns an IncludeByNameFunc which includes files that match
|
||||||
// one of the patterns, ignoring the casing of the filenames.
|
// 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))
|
lowerPatterns := make([]string, len(patterns))
|
||||||
for index, path := range patterns {
|
for index, path := range patterns {
|
||||||
lowerPatterns[index] = strings.ToLower(path)
|
lowerPatterns[index] = strings.ToLower(path)
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ func ParseVSSConfig(o options.Options) (VSSConfig, error) {
|
|||||||
type ErrorHandler func(item string, err error)
|
type ErrorHandler func(item string, err error)
|
||||||
|
|
||||||
// MessageHandler is used to report errors/messages via callbacks.
|
// 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.
|
// volumeFilter is used to filter volumes by their mount point or GUID path.
|
||||||
type volumeFilter func(volume string) bool
|
type volumeFilter func(volume string) bool
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ type commandReader struct {
|
|||||||
alreadyClosedReadErr error
|
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 {
|
if len(args) == 0 {
|
||||||
return nil, fmt.Errorf("no command was specified as argument")
|
return nil, fmt.Errorf("no command was specified as argument")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestCommandReaderSuccess(t *testing.T) {
|
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)
|
test.OK(t, err)
|
||||||
|
|
||||||
_, err = io.Copy(io.Discard, reader)
|
_, err = io.Copy(io.Discard, reader)
|
||||||
@@ -23,7 +23,7 @@ func TestCommandReaderSuccess(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCommandReaderFail(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)
|
test.OK(t, err)
|
||||||
|
|
||||||
_, err = io.Copy(io.Discard, reader)
|
_, err = io.Copy(io.Discard, reader)
|
||||||
@@ -31,17 +31,17 @@ func TestCommandReaderFail(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCommandReaderInvalid(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")
|
test.Assert(t, err != nil, "missing error")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCommandReaderEmptyArgs(t *testing.T) {
|
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")
|
test.Assert(t, err != nil, "missing error")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCommandReaderOutput(t *testing.T) {
|
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)
|
test.OK(t, err)
|
||||||
|
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
@@ -56,7 +56,7 @@ func TestCommandReaderOutput(t *testing.T) {
|
|||||||
func TestCommandReaderQuickClose(t *testing.T) {
|
func TestCommandReaderQuickClose(t *testing.T) {
|
||||||
ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second)
|
ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second)
|
||||||
defer cancel()
|
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.OK(t, err)
|
||||||
|
|
||||||
// test that close returns before the context expires
|
// test that close returns before the context expires
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ func TestOverwriteXattrWithSelectFilter(t *testing.T) {
|
|||||||
file := filepath.Join(dir, "file2")
|
file := filepath.Join(dir, "file2")
|
||||||
rtest.OK(t, os.WriteFile(file, []byte("hello world"), 0o600))
|
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.*
|
// Set a filter as if the user passed in --include-xattr user.*
|
||||||
xattrSelectFilter1 := func(xattrName string) bool {
|
xattrSelectFilter1 := func(xattrName string) bool {
|
||||||
|
|||||||
@@ -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.
|
// 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)
|
loc, err := location.Parse(backends, s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", nil, errors.Fatalf("parsing repository location failed: %v", err)
|
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.
|
// 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)
|
factory := gopts.Backends.Lookup(scheme)
|
||||||
if factory == nil {
|
if factory == nil {
|
||||||
return nil, errors.Fatalf("invalid backend: %q", scheme)
|
return nil, errors.Fatalf("invalid backend: %q", scheme)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ type Options map[string]string
|
|||||||
var opts []Help
|
var opts []Help
|
||||||
|
|
||||||
// Register allows registering options so that they can be listed with List.
|
// 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)
|
opts = appendAllOptions(opts, ns, cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ func List() (list []Help) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// appendAllOptions appends all options in cfg to opts, sorted by namespace.
|
// 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) {
|
for _, opt := range listOptions(cfg) {
|
||||||
opt.Namespace = ns
|
opt.Namespace = ns
|
||||||
opts = append(opts, opt)
|
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.
|
// 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
|
// resolve indirection if cfg is a pointer
|
||||||
v := reflect.Indirect(reflect.ValueOf(cfg))
|
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`.
|
// Apply sets the options on dst via reflection, using the struct tag `option`.
|
||||||
// The namespace argument (ns) is only used for error messages.
|
// 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()
|
v := reflect.ValueOf(dst).Elem()
|
||||||
|
|
||||||
fields := make(map[string]reflect.StructField)
|
fields := make(map[string]reflect.StructField)
|
||||||
|
|||||||
@@ -247,7 +247,7 @@ func TestListOptions(t *testing.T) {
|
|||||||
}{}
|
}{}
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
cfg interface{}
|
cfg any
|
||||||
opts []Help
|
opts []Help
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
@@ -298,11 +298,11 @@ func TestListOptions(t *testing.T) {
|
|||||||
|
|
||||||
func TestAppendAllOptions(t *testing.T) {
|
func TestAppendAllOptions(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
cfgs map[string]interface{}
|
cfgs map[string]any
|
||||||
opts []Help
|
opts []Help
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
map[string]interface{}{
|
map[string]any{
|
||||||
"local": struct {
|
"local": struct {
|
||||||
Foo string `option:"foo" help:"bar text help"`
|
Foo string `option:"foo" help:"bar text help"`
|
||||||
}{},
|
}{},
|
||||||
|
|||||||
@@ -44,11 +44,11 @@ var lockerInst = &locker{
|
|||||||
|
|
||||||
// LockRepo acquires a repository lock. The returned context is cancelled when
|
// LockRepo acquires a repository lock. The returned context is cancelled when
|
||||||
// Unlock is called; cancelling the original context stops lock refresh.
|
// 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)
|
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 lock *lockHandle
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
@@ -121,7 +121,7 @@ type refreshLockRequest struct {
|
|||||||
result chan bool
|
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")
|
debug.Log("start")
|
||||||
lock := unlocker.lock
|
lock := unlocker.lock
|
||||||
ticker := time.NewTicker(l.refreshInterval)
|
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
|
// time.Now() might use a monotonic timer which is paused during standby
|
||||||
// convert to unix time to ensure we compare real time values
|
// convert to unix time to ensure we compare real time values
|
||||||
lastRefresh := time.Now().UnixNano()
|
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)
|
freeze := backend.AsBackend[backend.FreezeBackend](be)
|
||||||
if freeze != nil {
|
if freeze != nil {
|
||||||
debug.Log("freezing backend")
|
debug.Log("freezing backend")
|
||||||
|
|||||||
@@ -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) {
|
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, err)
|
||||||
rtest.OK(t, wrappedCtx.Err())
|
rtest.OK(t, wrappedCtx.Err())
|
||||||
return unlock, wrappedCtx
|
return unlock, wrappedCtx
|
||||||
@@ -73,10 +73,10 @@ func TestLockConflict(t *testing.T) {
|
|||||||
repo, be := openLockTestRepo(t, nil)
|
repo, be := openLockTestRepo(t, nil)
|
||||||
repo2 := TestOpenBackend(t, be)
|
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)
|
rtest.OK(t, err)
|
||||||
defer unlock()
|
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 {
|
if err == nil {
|
||||||
t.Fatal("second lock should have failed")
|
t.Fatal("second lock should have failed")
|
||||||
}
|
}
|
||||||
@@ -237,14 +237,14 @@ func TestLockWaitTimeout(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
repo, _ := openLockTestRepo(t, nil)
|
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)
|
rtest.OK(t, err)
|
||||||
defer elock()
|
defer elock()
|
||||||
|
|
||||||
retryLock := 200 * time.Millisecond
|
retryLock := 200 * time.Millisecond
|
||||||
|
|
||||||
start := time.Now()
|
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)
|
duration := time.Since(start)
|
||||||
|
|
||||||
rtest.Assert(t, err != nil,
|
rtest.Assert(t, err != nil,
|
||||||
@@ -259,7 +259,7 @@ func TestLockWaitCancel(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
repo, _ := openLockTestRepo(t, nil)
|
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)
|
rtest.OK(t, err)
|
||||||
defer elock()
|
defer elock()
|
||||||
|
|
||||||
@@ -270,7 +270,7 @@ func TestLockWaitCancel(t *testing.T) {
|
|||||||
ctx, cancel := context.WithCancel(context.TODO())
|
ctx, cancel := context.WithCancel(context.TODO())
|
||||||
time.AfterFunc(cancelAfter, cancel)
|
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)
|
duration := time.Since(start)
|
||||||
|
|
||||||
rtest.Assert(t, err != nil,
|
rtest.Assert(t, err != nil,
|
||||||
@@ -285,7 +285,7 @@ func TestLockWaitSuccess(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
repo, _ := openLockTestRepo(t, nil)
|
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)
|
rtest.OK(t, err)
|
||||||
|
|
||||||
retryLock := 200 * time.Millisecond
|
retryLock := 200 * time.Millisecond
|
||||||
@@ -295,7 +295,7 @@ func TestLockWaitSuccess(t *testing.T) {
|
|||||||
elock()
|
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)
|
rtest.OK(t, err)
|
||||||
unlock()
|
unlock()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ type repackBlobSet interface {
|
|||||||
Len() int
|
Len() int
|
||||||
}
|
}
|
||||||
|
|
||||||
type LogFunc func(msg string, args ...interface{})
|
type LogFunc func(msg string, args ...any)
|
||||||
|
|
||||||
// CopyBlobs takes a list of packs together with a list of blobs contained in
|
// CopyBlobs takes a list of packs together with a list of blobs contained in
|
||||||
// these packs. Each pack is loaded and the blobs listed in keepBlobs is saved
|
// these packs. Each pack is loaded and the blobs listed in keepBlobs is saved
|
||||||
@@ -42,7 +42,7 @@ func CopyBlobs(
|
|||||||
debug.Log("repacking %d packs while keeping %d blobs", len(packs), keepBlobs.Len())
|
debug.Log("repacking %d packs while keeping %d blobs", len(packs), keepBlobs.Len())
|
||||||
|
|
||||||
if logf == nil {
|
if logf == nil {
|
||||||
logf = func(_ string, _ ...interface{}) {}
|
logf = func(_ string, _ ...any) {}
|
||||||
}
|
}
|
||||||
p.SetMax(uint64(len(packs)))
|
p.SetMax(uint64(len(packs)))
|
||||||
defer p.Done()
|
defer p.Done()
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ func (r *Repository) PackSize() uint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UseCache replaces the backend with the wrapped cache.
|
// UseCache replaces the backend with the wrapped cache.
|
||||||
func (r *Repository) UseCache(c *cache.Cache, errorLog func(string, ...interface{})) {
|
func (r *Repository) UseCache(c *cache.Cache, errorLog func(string, ...any)) {
|
||||||
if c == nil {
|
if c == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type logger interface {
|
type logger interface {
|
||||||
Logf(format string, args ...interface{})
|
Logf(format string, args ...any)
|
||||||
}
|
}
|
||||||
|
|
||||||
var paramsOnce sync.Once
|
var paramsOnce sync.Once
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
// LoadJSONUnpacked decrypts the data and afterwards calls json.Unmarshal on
|
// LoadJSONUnpacked decrypts the data and afterwards calls json.Unmarshal on
|
||||||
// the item.
|
// the item.
|
||||||
func LoadJSONUnpacked(ctx context.Context, repo LoaderUnpacked, t FileType, id ID, item interface{}) (err error) {
|
func LoadJSONUnpacked(ctx context.Context, repo LoaderUnpacked, t FileType, id ID, item any) (err error) {
|
||||||
buf, err := repo.LoadUnpacked(ctx, t, id)
|
buf, err := repo.LoadUnpacked(ctx, t, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -21,7 +21,7 @@ func LoadJSONUnpacked(ctx context.Context, repo LoaderUnpacked, t FileType, id I
|
|||||||
|
|
||||||
// SaveJSONUnpacked serialises item as JSON and encrypts and saves it in the
|
// SaveJSONUnpacked serialises item as JSON and encrypts and saves it in the
|
||||||
// backend as type t, without a pack. It returns the storage hash.
|
// backend as type t, without a pack. It returns the storage hash.
|
||||||
func SaveJSONUnpacked[FT FileTypes](ctx context.Context, repo SaverUnpacked[FT], t FT, item interface{}) (ID, error) {
|
func SaveJSONUnpacked[FT FileTypes](ctx context.Context, repo SaverUnpacked[FT], t FT, item any) (ID, error) {
|
||||||
debug.Log("save new blob %v", t)
|
debug.Log("save new blob %v", t)
|
||||||
plaintext, err := json.Marshal(item)
|
plaintext, err := json.Marshal(item)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+12
-12
@@ -38,24 +38,24 @@ type Printer interface {
|
|||||||
|
|
||||||
// E reports an error. This message is always printed to stderr.
|
// E reports an error. This message is always printed to stderr.
|
||||||
// Appends a newline if not present.
|
// Appends a newline if not present.
|
||||||
E(msg string, args ...interface{})
|
E(msg string, args ...any)
|
||||||
// S prints a message, this is should only be used for very important messages
|
// S prints a message, this is should only be used for very important messages
|
||||||
// that are not errors. The message is even printed if --quiet is specified.
|
// that are not errors. The message is even printed if --quiet is specified.
|
||||||
// Appends a newline if not present.
|
// Appends a newline if not present.
|
||||||
S(msg string, args ...interface{})
|
S(msg string, args ...any)
|
||||||
// PT prints a message if verbosity >= 1 (neither --quiet nor --verbose is specified)
|
// PT prints a message if verbosity >= 1 (neither --quiet nor --verbose is specified)
|
||||||
// and stdout points to a terminal.
|
// and stdout points to a terminal.
|
||||||
// This is used for informational messages.
|
// This is used for informational messages.
|
||||||
PT(msg string, args ...interface{})
|
PT(msg string, args ...any)
|
||||||
// P prints a message if verbosity >= 1 (neither --quiet nor --verbose is specified),
|
// P prints a message if verbosity >= 1 (neither --quiet nor --verbose is specified),
|
||||||
// this is used for normal messages which are not errors. Appends a newline if not present.
|
// this is used for normal messages which are not errors. Appends a newline if not present.
|
||||||
P(msg string, args ...interface{})
|
P(msg string, args ...any)
|
||||||
// V prints a message if verbosity >= 2 (equivalent to --verbose), this is used for
|
// V prints a message if verbosity >= 2 (equivalent to --verbose), this is used for
|
||||||
// verbose messages. Appends a newline if not present.
|
// verbose messages. Appends a newline if not present.
|
||||||
V(msg string, args ...interface{})
|
V(msg string, args ...any)
|
||||||
// VV prints a message if verbosity >= 3 (equivalent to --verbose=2), this is used for
|
// VV prints a message if verbosity >= 3 (equivalent to --verbose=2), this is used for
|
||||||
// debug messages. Appends a newline if not present.
|
// debug messages. Appends a newline if not present.
|
||||||
VV(msg string, args ...interface{})
|
VV(msg string, args ...any)
|
||||||
}
|
}
|
||||||
|
|
||||||
// noopPrinter discards all messages.
|
// noopPrinter discards all messages.
|
||||||
@@ -79,14 +79,14 @@ func (*noopPrinter) NewCounterTerminalOnly(_ string) Counter {
|
|||||||
return NoopCounter
|
return NoopCounter
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*noopPrinter) E(_ string, _ ...interface{}) {}
|
func (*noopPrinter) E(_ string, _ ...any) {}
|
||||||
|
|
||||||
func (*noopPrinter) S(_ string, _ ...interface{}) {}
|
func (*noopPrinter) S(_ string, _ ...any) {}
|
||||||
|
|
||||||
func (*noopPrinter) PT(_ string, _ ...interface{}) {}
|
func (*noopPrinter) PT(_ string, _ ...any) {}
|
||||||
|
|
||||||
func (*noopPrinter) P(_ string, _ ...interface{}) {}
|
func (*noopPrinter) P(_ string, _ ...any) {}
|
||||||
|
|
||||||
func (*noopPrinter) V(_ string, _ ...interface{}) {}
|
func (*noopPrinter) V(_ string, _ ...any) {}
|
||||||
|
|
||||||
func (*noopPrinter) VV(_ string, _ ...interface{}) {}
|
func (*noopPrinter) VV(_ string, _ ...any) {}
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ type fileInfo struct {
|
|||||||
inProgress bool
|
inProgress bool
|
||||||
sparse bool
|
sparse bool
|
||||||
size int64
|
size int64
|
||||||
location string // file on local filesystem relative to restorer basedir
|
location string // file on local filesystem relative to restorer basedir
|
||||||
blobs interface{} // blobs of the file
|
blobs any // blobs of the file
|
||||||
state *fileState
|
state *fileState
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import (
|
|||||||
"github.com/restic/restic/internal/ui/progress"
|
"github.com/restic/restic/internal/ui/progress"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Node interface{}
|
type Node any
|
||||||
|
|
||||||
type Snapshot struct {
|
type Snapshot struct {
|
||||||
Nodes map[string]Node
|
Nodes map[string]Node
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ func findHash(buf []byte, filename string) (hash []byte, err error) {
|
|||||||
return nil, fmt.Errorf("hash for file %v not found", filename)
|
return nil, fmt.Errorf("hash for file %v not found", filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
func extractToFile(buf []byte, filename, target string, printf func(string, ...interface{})) error {
|
func extractToFile(buf []byte, filename, target string, printf func(string, ...any)) error {
|
||||||
var rd io.Reader = bytes.NewReader(buf)
|
var rd io.Reader = bytes.NewReader(buf)
|
||||||
switch filepath.Ext(filename) {
|
switch filepath.Ext(filename) {
|
||||||
case ".bz2":
|
case ".bz2":
|
||||||
@@ -112,9 +112,9 @@ func extractToFile(buf []byte, filename, target string, printf func(string, ...i
|
|||||||
// DownloadLatestStableRelease downloads the latest stable released version of
|
// DownloadLatestStableRelease downloads the latest stable released version of
|
||||||
// restic and saves it to target. It returns the version string for the newest
|
// restic and saves it to target. It returns the version string for the newest
|
||||||
// version. The function printf is used to print progress information.
|
// version. The function printf is used to print progress information.
|
||||||
func DownloadLatestStableRelease(ctx context.Context, target, currentVersion string, printf func(string, ...interface{})) (version string, err error) {
|
func DownloadLatestStableRelease(ctx context.Context, target, currentVersion string, printf func(string, ...any)) (version string, err error) {
|
||||||
if printf == nil {
|
if printf == nil {
|
||||||
printf = func(string, ...interface{}) {}
|
printf = func(string, ...any) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("find latest release of restic at GitHub\n")
|
printf("find latest release of restic at GitHub\n")
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestExtractToFileZip(t *testing.T) {
|
func TestExtractToFileZip(t *testing.T) {
|
||||||
printf := func(string, ...interface{}) {}
|
printf := func(string, ...any) {}
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
|
|
||||||
ext := "zip"
|
ext := "zip"
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ func getGithubData(ctx context.Context, url string) ([]byte, error) {
|
|||||||
return buf, nil
|
return buf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getGithubDataFile(ctx context.Context, assets []Asset, suffix string, printf func(string, ...interface{})) (filename string, data []byte, err error) {
|
func getGithubDataFile(ctx context.Context, assets []Asset, suffix string, printf func(string, ...any)) (filename string, data []byte, err error) {
|
||||||
var url string
|
var url string
|
||||||
for _, a := range assets {
|
for _, a := range assets {
|
||||||
if strings.HasSuffix(a.Name, suffix) {
|
if strings.HasSuffix(a.Name, suffix) {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Assert fails the test if the condition is false.
|
// Assert fails the test if the condition is false.
|
||||||
func Assert(tb testing.TB, condition bool, msg string, v ...interface{}) {
|
func Assert(tb testing.TB, condition bool, msg string, v ...any) {
|
||||||
tb.Helper()
|
tb.Helper()
|
||||||
if !condition {
|
if !condition {
|
||||||
tb.Fatalf("\033[31m"+msg+"\033[39m\n\n", v...)
|
tb.Fatalf("\033[31m"+msg+"\033[39m\n\n", v...)
|
||||||
@@ -56,7 +56,7 @@ func Equals[T any](tb testing.TB, exp, act T, msgs ...string) {
|
|||||||
if length == 1 {
|
if length == 1 {
|
||||||
msgString = msgs[0]
|
msgString = msgs[0]
|
||||||
} else if length > 1 {
|
} else if length > 1 {
|
||||||
args := make([]interface{}, length-1)
|
args := make([]any, length-1)
|
||||||
for i, msg := range msgs[1:] {
|
for i, msg := range msgs[1:] {
|
||||||
args[i] = msg
|
args[i] = msg
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,11 +30,11 @@ func NewJSONProgress(term ui.Terminal, verbosity uint) ProgressPrinter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *jsonProgress) print(status interface{}) {
|
func (b *jsonProgress) print(status any) {
|
||||||
b.term.Print(ui.ToJSONString(status))
|
b.term.Print(ui.ToJSONString(status))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *jsonProgress) error(status interface{}) {
|
func (b *jsonProgress) error(status any) {
|
||||||
b.term.Error(ui.ToJSONString(status))
|
b.term.Error(ui.ToJSONString(status))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ func ParseBytes(s string) (int64, error) {
|
|||||||
return value, nil
|
return value, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ToJSONString(status interface{}) string {
|
func ToJSONString(status any) string {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
err := json.NewEncoder(buf).Encode(status)
|
err := json.NewEncoder(buf).Encode(status)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -66,33 +66,33 @@ func (t *terminalPrinter) NewCounterTerminalOnly(description string) restic.Coun
|
|||||||
return newProgressMax(t.v > 0 && t.term.OutputIsTerminal(), 0, description, t.term)
|
return newProgressMax(t.v > 0 && t.term.OutputIsTerminal(), 0, description, t.term)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *terminalPrinter) E(msg string, args ...interface{}) {
|
func (t *terminalPrinter) E(msg string, args ...any) {
|
||||||
t.term.Error(fmt.Sprintf(msg, args...))
|
t.term.Error(fmt.Sprintf(msg, args...))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *terminalPrinter) S(msg string, args ...interface{}) {
|
func (t *terminalPrinter) S(msg string, args ...any) {
|
||||||
t.term.Print(fmt.Sprintf(msg, args...))
|
t.term.Print(fmt.Sprintf(msg, args...))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *terminalPrinter) PT(msg string, args ...interface{}) {
|
func (t *terminalPrinter) PT(msg string, args ...any) {
|
||||||
if t.term.OutputIsTerminal() && t.v >= 1 {
|
if t.term.OutputIsTerminal() && t.v >= 1 {
|
||||||
t.term.Print(fmt.Sprintf(msg, args...))
|
t.term.Print(fmt.Sprintf(msg, args...))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *terminalPrinter) P(msg string, args ...interface{}) {
|
func (t *terminalPrinter) P(msg string, args ...any) {
|
||||||
if t.v >= 1 {
|
if t.v >= 1 {
|
||||||
t.term.Print(fmt.Sprintf(msg, args...))
|
t.term.Print(fmt.Sprintf(msg, args...))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *terminalPrinter) V(msg string, args ...interface{}) {
|
func (t *terminalPrinter) V(msg string, args ...any) {
|
||||||
if t.v >= 2 {
|
if t.v >= 2 {
|
||||||
t.term.Print(fmt.Sprintf(msg, args...))
|
t.term.Print(fmt.Sprintf(msg, args...))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *terminalPrinter) VV(msg string, args ...interface{}) {
|
func (t *terminalPrinter) VV(msg string, args ...any) {
|
||||||
if t.v >= 3 {
|
if t.v >= 3 {
|
||||||
t.term.Print(fmt.Sprintf(msg, args...))
|
t.term.Print(fmt.Sprintf(msg, args...))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,11 +24,11 @@ func NewJSONProgress(terminal ui.Terminal, verbosity uint) ProgressPrinter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *jsonPrinter) print(status interface{}) {
|
func (t *jsonPrinter) print(status any) {
|
||||||
t.terminal.Print(ui.ToJSONString(status))
|
t.terminal.Print(ui.ToJSONString(status))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *jsonPrinter) error(status interface{}) {
|
func (t *jsonPrinter) error(status any) {
|
||||||
t.terminal.Error(ui.ToJSONString(status))
|
t.terminal.Error(ui.ToJSONString(status))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
type Table struct {
|
type Table struct {
|
||||||
columns []string
|
columns []string
|
||||||
templates []*template.Template
|
templates []*template.Template
|
||||||
data []interface{}
|
data []any
|
||||||
footer []string
|
footer []string
|
||||||
|
|
||||||
CellSeparator string
|
CellSeparator string
|
||||||
@@ -58,7 +58,7 @@ func (t *Table) AddColumn(header, format string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddRow adds a new row to the table, which is filled with data.
|
// AddRow adds a new row to the table, which is filled with data.
|
||||||
func (t *Table) AddRow(data interface{}) {
|
func (t *Table) AddRow(data any) {
|
||||||
t.data = append(t.data, data)
|
t.data = append(t.data, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// TestTree is used to construct a list of trees for testing the walker.
|
// TestTree is used to construct a list of trees for testing the walker.
|
||||||
type TestTree map[string]interface{}
|
type TestTree map[string]any
|
||||||
|
|
||||||
// TestFile is used to test the walker.
|
// TestFile is used to test the walker.
|
||||||
type TestFile struct {
|
type TestFile struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user