From 69165c09240354dacb33c743b4de2064f8a0db06 Mon Sep 17 00:00:00 2001 From: Nick Naumann Date: Mon, 11 Jul 2022 23:26:50 +0200 Subject: [PATCH] sync: add filter-sensitivity to --backup-dir option The old Overlapping function and corresponding tests have been removed, as it has been completely replaced by the OverlappingFilterCheck function. --- fs/operations/operations.go | 15 ++------------- fs/operations/operations_test.go | 29 ----------------------------- 2 files changed, 2 insertions(+), 42 deletions(-) diff --git a/fs/operations/operations.go b/fs/operations/operations.go index 0b0f9f75e..6f6b412cf 100644 --- a/fs/operations/operations.go +++ b/fs/operations/operations.go @@ -814,17 +814,6 @@ func fixRoot(f fs.Info) string { return s } -// Overlapping returns true if fdst and fsrc point to the same -// underlying Fs and they overlap. -func Overlapping(fdst, fsrc fs.Info) bool { - if !SameConfig(fdst, fsrc) { - return false - } - fdstRoot := fixRoot(fdst) - fsrcRoot := fixRoot(fsrc) - return strings.HasPrefix(fdstRoot, fsrcRoot) || strings.HasPrefix(fsrcRoot, fdstRoot) -} - // OverlappingFilterCheck returns true if fdst and fsrc point to the same // underlying Fs and they overlap without fdst being excluded by any filter rule. func OverlappingFilterCheck(ctx context.Context, fdst fs.Fs, fsrc fs.Fs) bool { @@ -1848,10 +1837,10 @@ func BackupDir(ctx context.Context, fdst fs.Fs, fsrc fs.Fs, srcFileName string) return nil, fserrors.FatalError(errors.New("parameter to --backup-dir has to be on the same remote as destination")) } if srcFileName == "" { - if Overlapping(fdst, backupDir) { + if OverlappingFilterCheck(ctx, backupDir, fdst) { return nil, fserrors.FatalError(errors.New("destination and parameter to --backup-dir mustn't overlap")) } - if Overlapping(fsrc, backupDir) { + if OverlappingFilterCheck(ctx, backupDir, fsrc) { return nil, fserrors.FatalError(errors.New("source and parameter to --backup-dir mustn't overlap")) } } else { diff --git a/fs/operations/operations_test.go b/fs/operations/operations_test.go index 34b88d6d1..20fcc61a0 100644 --- a/fs/operations/operations_test.go +++ b/fs/operations/operations_test.go @@ -1243,35 +1243,6 @@ func TestSame(t *testing.T) { } } -func TestOverlapping(t *testing.T) { - a := &testFsInfo{name: "name", root: "root"} - slash := string(os.PathSeparator) // native path separator - for _, test := range []struct { - name string - root string - expected bool - }{ - {"name", "root", true}, - {"namey", "root", false}, - {"name", "rooty", false}, - {"namey", "rooty", false}, - {"name", "roo", false}, - {"name", "root/toot", true}, - {"name", "root/toot/", true}, - {"name", "root" + slash + "toot", true}, - {"name", "root" + slash + "toot" + slash, true}, - {"name", "", true}, - {"name", "/", true}, - } { - b := &testFsInfo{name: test.name, root: test.root} - what := fmt.Sprintf("(%q,%q) vs (%q,%q)", a.name, a.root, b.name, b.root) - actual := operations.Overlapping(a, b) - assert.Equal(t, test.expected, actual, what) - actual = operations.Overlapping(b, a) - assert.Equal(t, test.expected, actual, what) - } -} - // testFs is for unit testing fs.Fs type testFs struct { testFsInfo