-
Notifications
You must be signed in to change notification settings - Fork 896
copier: add RemoveOptions.AllowWildcard #6827
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1954,6 +1954,7 @@ func testRemove(t *testing.T) { | |
| remove string | ||
| all bool | ||
| allowNotFound bool | ||
| allowWildcard bool | ||
| fail bool | ||
| removed []string | ||
| } | ||
|
|
@@ -2095,6 +2096,73 @@ func testRemove(t *testing.T) { | |
| all: true, | ||
| removed: []string{"subdir-a/subdir-e", "subdir-a/subdir-e/subdir-f"}, | ||
| }, | ||
| { | ||
| name: "wildcard-files", | ||
| remove: "subdir-a/file-*", | ||
| allowWildcard: true, | ||
| removed: []string{"subdir-a/file-a", "subdir-a/file-b"}, | ||
| }, | ||
| { | ||
| name: "wildcard-all-in-dir", | ||
| remove: "subdir-a/subdir-b/*", | ||
| allowWildcard: true, | ||
| all: true, | ||
| removed: []string{ | ||
| "subdir-a/subdir-b/subdir-c", | ||
| "subdir-a/subdir-b/subdir-c/parent", | ||
| "subdir-a/subdir-b/subdir-c/link-b", | ||
| "subdir-a/subdir-b/subdir-c/root", | ||
| }, | ||
| }, | ||
| { | ||
| name: "wildcard-no-match", | ||
| remove: "subdir-a/nonexistent-*", | ||
| allowWildcard: true, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without |
||
| }, | ||
| { | ||
| name: "wildcard-allow-not-found", | ||
| remove: "subdir-a/file-*", | ||
| allowWildcard: true, | ||
| allowNotFound: true, | ||
| removed: []string{"subdir-a/file-a", "subdir-a/file-b"}, | ||
| }, | ||
| { | ||
| name: "wildcard-dir-without-all", | ||
| remove: "subdir-a/subdir-*", | ||
| allowWildcard: true, | ||
| all: false, | ||
| fail: true, | ||
| }, | ||
| { | ||
| name: "wildcard-empty-dir", | ||
| remove: "subdir-a/subdir-d", | ||
| allowWildcard: true, | ||
| all: false, | ||
| removed: []string{"subdir-a/subdir-d"}, | ||
| }, | ||
| { | ||
| name: "wildcard-literal-path", | ||
| remove: "subdir-a/file-a", | ||
| allowWildcard: true, | ||
| removed: []string{"subdir-a/file-a"}, | ||
| }, | ||
| { | ||
| name: "wildcard-literal-missing", | ||
| remove: "subdir-a/file-nonexistent", | ||
| allowWildcard: true, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without |
||
| }, | ||
| { | ||
| name: "wildcard-char-class", | ||
| remove: "subdir-a/file-[ab]", | ||
| allowWildcard: true, | ||
| removed: []string{"subdir-a/file-a", "subdir-a/file-b"}, | ||
| }, | ||
| { | ||
| name: "wildcard-question-mark", | ||
| remove: "subdir-a/file-?", | ||
| allowWildcard: true, | ||
| removed: []string{"subdir-a/file-a", "subdir-a/file-b"}, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
@@ -2105,7 +2173,7 @@ func testRemove(t *testing.T) { | |
| dir, err := makeContextFromArchive(t, makeArchive(testArchives[i].headers, nil), "") | ||
| require.NoErrorf(t, err, "error creating context from archive %q, topdir=%q", testArchives[i].name, "") | ||
| root := dir | ||
| options := RemoveOptions{All: testCase.all, AllowNotFound: testCase.allowNotFound} | ||
| options := RemoveOptions{All: testCase.all, AllowNotFound: testCase.allowNotFound, AllowWildcard: testCase.allowWildcard} | ||
| beforeNames := make(map[string]struct{}) | ||
| err = filepath.WalkDir(dir, func(path string, _ fs.DirEntry, err error) error { | ||
| if err != nil { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to be catching cases where the returned set of targets has
len() == 0whenAllowNotFoundisn't set, and returning an error, asGlob()will only return an error for an invalid pattern.AllowWildcarddoesn't always mean that there's a wildcard being used, and I don't know that we want to effectively ignore not-found errors when it's set.