diff --git a/cmd/difference_test.go b/cmd/difference_test.go index 6988c03b..796e4d95 100644 --- a/cmd/difference_test.go +++ b/cmd/difference_test.go @@ -24,26 +24,40 @@ import ( var testCases = []struct { pattern []string - object string + srcSuffix string match bool + + typ ClientURLType }{ - {nil, "testfile", false}, - {[]string{"test*"}, "testfile", true}, - {[]string{"file*"}, "file/abc/bcd/def", true}, - {[]string{"*"}, "file/abc/bcd/def", true}, - {[]string{""}, "file/abc/bcd/def", false}, - {[]string{"abc*"}, "file/abc/bcd/def", false}, - {[]string{"abc*", "*abc/*"}, "file/abc/bcd/def", true}, - {[]string{"*.txt"}, "file/abc/bcd/def.txt", true}, - {[]string{".*"}, ".sys", true}, - {[]string{"*."}, ".sys.", true}, + {nil, "testfile", false, objectStorage}, + {[]string{"test*"}, "testfile", true, objectStorage}, + {[]string{"file*"}, "file/abc/bcd/def", true, objectStorage}, + {[]string{"*"}, "file/abc/bcd/def", true, objectStorage}, + {[]string{""}, "file/abc/bcd/def", false, objectStorage}, + {[]string{"abc*"}, "file/abc/bcd/def", false, objectStorage}, + {[]string{"abc*", "*abc/*"}, "file/abc/bcd/def", true, objectStorage}, + {[]string{"*.txt"}, "file/abc/bcd/def.txt", true, objectStorage}, + {[]string{".*"}, ".sys", true, objectStorage}, + {[]string{"*."}, ".sys.", true, objectStorage}, + {nil, "testfile", false, fileSystem}, + {[]string{"test*"}, "testfile", true, fileSystem}, + {[]string{"file*"}, "file/abc/bcd/def", true, fileSystem}, + {[]string{"*"}, "file/abc/bcd/def", true, fileSystem}, + {[]string{""}, "file/abc/bcd/def", false, fileSystem}, + {[]string{"abc*"}, "file/abc/bcd/def", false, fileSystem}, + {[]string{"abc*", "*abc/*"}, "file/abc/bcd/def", true, fileSystem}, + {[]string{"abc*", "*abc/*"}, "/file/abc/bcd/def", true, fileSystem}, + {[]string{"*.txt"}, "file/abc/bcd/def.txt", true, fileSystem}, + {[]string{"*.txt"}, "/file/abc/bcd/def.txt", true, fileSystem}, + {[]string{".*"}, ".sys", true, fileSystem}, + {[]string{"*."}, ".sys.", true, fileSystem}, } func TestExcludeOptions(t *testing.T) { for _, test := range testCases { - if matchExcludeOptions(test.pattern, test.object) != test.match { - t.Fatalf("Unexpected result %t, with pattern %s and object %s \n", !test.match, test.pattern, test.object) + if matchExcludeOptions(test.pattern, test.srcSuffix, test.typ) != test.match { + t.Fatalf("Unexpected result %t, with pattern %s and srcSuffix %s \n", !test.match, test.pattern, test.srcSuffix) } } } diff --git a/cmd/mirror-main.go b/cmd/mirror-main.go index 675d11d7..aab22b55 100644 --- a/cmd/mirror-main.go +++ b/cmd/mirror-main.go @@ -628,7 +628,7 @@ func (mj *mirrorJob) watchMirrorEvents(ctx context.Context, events []EventInfo) // joined to the targetURL. sourceSuffix := strings.TrimPrefix(eventPath, sourceURLFull) // Skip the object, if it matches the Exclude options provided - if matchExcludeOptions(mj.opts.excludeOptions, sourceSuffix) { + if matchExcludeOptions(mj.opts.excludeOptions, sourceSuffix, sourceURL.Type) { continue } diff --git a/cmd/mirror-url.go b/cmd/mirror-url.go index e98f8eae..fe816225 100644 --- a/cmd/mirror-url.go +++ b/cmd/mirror-url.go @@ -89,7 +89,15 @@ func checkMirrorSyntax(ctx context.Context, cliCtx *cli.Context, encKeyDB map[st return } -func matchExcludeOptions(excludeOptions []string, srcSuffix string) bool { +func matchExcludeOptions(excludeOptions []string, srcSuffix string, typ ClientURLType) bool { + // if type is file system, remove leading slash + if typ == fileSystem { + if strings.HasPrefix(srcSuffix, "/") { + srcSuffix = srcSuffix[1:] + } else if runtime.GOOS == "windows" && strings.HasPrefix(srcSuffix, `\`) { + srcSuffix = srcSuffix[1:] + } + } for _, pattern := range excludeOptions { if wildcard.Match(pattern, srcSuffix) { return true @@ -146,13 +154,13 @@ func deltaSourceTarget(ctx context.Context, sourceURL, targetURL string, opts mi srcSuffix := strings.TrimPrefix(diffMsg.FirstURL, sourceURL) // Skip the source object if it matches the Exclude options provided - if matchExcludeOptions(opts.excludeOptions, srcSuffix) { + if matchExcludeOptions(opts.excludeOptions, srcSuffix, newClientURL(sourceURL).Type) { continue } tgtSuffix := strings.TrimPrefix(diffMsg.SecondURL, targetURL) // Skip the target object if it matches the Exclude options provided - if matchExcludeOptions(opts.excludeOptions, tgtSuffix) { + if matchExcludeOptions(opts.excludeOptions, tgtSuffix, newClientURL(targetURL).Type) { continue }