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.
This commit is contained in:
parent
8c19b355a5
commit
11be920e90
2 changed files with 2 additions and 42 deletions
|
@ -815,17 +815,6 @@ func fixRoot(f fs.Info) string {
|
||||||
return s
|
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
|
// OverlappingFilterCheck returns true if fdst and fsrc point to the same
|
||||||
// underlying Fs and they overlap without fdst being excluded by any filter rule.
|
// 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 {
|
func OverlappingFilterCheck(ctx context.Context, fdst fs.Fs, fsrc fs.Fs) bool {
|
||||||
|
@ -1849,10 +1838,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"))
|
return nil, fserrors.FatalError(errors.New("parameter to --backup-dir has to be on the same remote as destination"))
|
||||||
}
|
}
|
||||||
if srcFileName == "" {
|
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"))
|
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"))
|
return nil, fserrors.FatalError(errors.New("source and parameter to --backup-dir mustn't overlap"))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -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
|
// testFs is for unit testing fs.Fs
|
||||||
type testFs struct {
|
type testFs struct {
|
||||||
testFsInfo
|
testFsInfo
|
||||||
|
|
Loading…
Reference in a new issue