Skip to content

copier: add RemoveOptions.AllowWildcard#6827

Open
akca wants to merge 1 commit into
containers:mainfrom
akca:opfile-allowwildcard
Open

copier: add RemoveOptions.AllowWildcard#6827
akca wants to merge 1 commit into
containers:mainfrom
akca:opfile-allowwildcard

Conversation

@akca
Copy link
Copy Markdown
Contributor

@akca akca commented Apr 30, 2026

What type of PR is this?

/kind feature

What this PR does / why we need it:

Adds AllowWildcard as a boolean field to copier.RemoveOptions. When set, the path is expanded as a glob pattern and each match is removed. This aligns buildah's copier with BuildKit's FileActionRm.AllowWildcard behavior.

How to verify it

go test ./copier -run TestRemove -v

New test cases cover: *, ?, [ab] patterns, zero matches, interaction with All and AllowNotFound flags.

Which issue(s) this PR fixes:

Fixes #6806

Special notes for your reviewer:

Does this PR introduce a user-facing change?

copier: add `RemoveOptions.AllowWildcard` to support glob patterns in remove operations.

Add AllowWildcard as a boolean field to copier.RemoveOptions. When set, the path is expanded as a glob pattern and each match is removed.

Signed-off-by: Fatih Akca <fatihakca5@gmail.com>
@akca akca force-pushed the opfile-allowwildcard branch from d683b1c to c2719f8 Compare April 30, 2026 15:39
@packit-as-a-service
Copy link
Copy Markdown

Ephemeral COPR build failed. @containers/packit-build please check.

@akca akca marked this pull request as ready for review April 30, 2026 15:42
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Apr 30, 2026
@TomSweeneyRedHat
Copy link
Copy Markdown
Member

I have restarted the failed check, which didn't appear related to these changes.

@TomSweeneyRedHat
Copy link
Copy Markdown
Member

LGTM
@nalind PTAL

Copy link
Copy Markdown
Member

@nalind nalind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks about right, though I'm not clear on whether the cases where the wildcard doesn't match anything should expect to get an error back. Do we know what the expected behavior there is?

Comment thread copier/copier_test.go
{
name: "wildcard-literal-missing",
remove: "subdir-a/file-nonexistent",
allowWildcard: true,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without allowNotFound and all set (i.e., both false), should an error be returned, causing this test to fail because fail wasn't set?

Comment thread copier/copier_test.go
{
name: "wildcard-no-match",
remove: "subdir-a/nonexistent-*",
allowWildcard: true,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without allowNotFound and all set (i.e., both false), should an error be returned, causing this test to fail because fail wasn't set?

Comment thread copier/copier.go
targets, err = extendedGlob(req.Directory)
if err != nil {
return errorResponse("copier: remove: glob %q: %v", req.Directory, err)
}
Copy link
Copy Markdown
Member

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() == 0 when AllowNotFound isn't set, and returning an error, as Glob() will only return an error for an invalid pattern.
AllowWildcard doesn'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.

@akca
Copy link
Copy Markdown
Contributor Author

akca commented May 8, 2026

Looks about right, though I'm not clear on whether the cases where the wildcard doesn't match anything should expect to get an error back. Do we know what the expected behavior there is?

Checked BuildKit's implementation of the same flag (here). When AllowWildcard is set and the pattern matches nothing, it silently succeeds. AllowNotFound doesn't affect that; it only controls whether individually resolved paths that don't exist are an error.

Test cases here expecting success on zero matches follow that same behaviour. @nalind what do you think?

Copy link
Copy Markdown
Member

@nalind nalind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks about right, though I'm not clear on whether the cases where the wildcard doesn't match anything should expect to get an error back. Do we know what the expected behavior there is?

Checked BuildKit's implementation of the same flag (here). When AllowWildcard is set and the pattern matches nothing, it silently succeeds. AllowNotFound doesn't affect that; it only controls whether individually resolved paths that don't exist are an error.

I think that's a wrinkle that would be great to note in the godoc, if only for future-me's benefit. Not a blocker, though.

Test cases here expecting success on zero matches follow that same behaviour. @nalind what do you think?

That's the use case we want to be compatible with, so the tests are good as-is.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for Op_File.Actions.FileAction_Rm.AllowWildcard

3 participants