fix: mirror with local path (#4825)
This commit is contained in:
+27
-13
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -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
|
||||
}
|
||||
|
||||
|
||||
+11
-3
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user