Skip to content

Add support for symbolic chmod options#6778

Open
nickjwhite wants to merge 1 commit into
containers:mainfrom
nickjwhite:better-chmod
Open

Add support for symbolic chmod options#6778
nickjwhite wants to merge 1 commit into
containers:mainfrom
nickjwhite:better-chmod

Conversation

@nickjwhite
Copy link
Copy Markdown

@nickjwhite nickjwhite commented Apr 9, 2026

What type of PR is this?

/kind feature

What this PR does / why we need it:

This adds an optional Chmod string option to GetOptions and PutOptions. If set, this overrides the ChmodDirs and ChmodFiles options. If unset, they continue to work as before.

The --chmod option to buildah add and buildah copy works with symbolic as well as numeric arguments.

How to verify it

See extra bats tests and copier tests.

Which issue(s) this PR fixes:

Fixes #6066

Special notes for your reviewer:

Note that I'm not sure whether the extra tests in commit_test.go add much value over those in copier/copier_test.go, but I used them while working on this change, so I figured I'd just include them.

Also I'm not sure if this is the way you want the vendored stuff to be included (I added the newly added directory after running 'make vendor') - let me know if I should do it differently.

#6732 suggested calling the new option in GetOptions & PutOptions ChmodStr, but I chose Chmod here because I think it's shorter and clearer.

Does this PR introduce a user-facing change?

The add and copy commands' --chmod argument now accepts symbolic notation, as well as the traditional numeric notation currently supported. Likewise copier's GetOptions and PutOptions now a Chmod option, which accepts numeric or symbolic notation, and if set overrides any ChmodDirs and ChmodFiles options.

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Apr 9, 2026
@packit-as-a-service
Copy link
Copy Markdown

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

@nickjwhite nickjwhite force-pushed the better-chmod branch 2 times, most recently from 0d82f4b to 42d5139 Compare April 9, 2026 15:34
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.

Overall this looks very good to me. A couple of quibbles about using test helper functions that would shorten them, and a question about calling mode.Parse() multiple times when reading.

Comment thread commit_test.go Outdated
Comment thread copier/copier.go Outdated
}
// force ownership and/or permissions, if requested
if options.Chmod != "" {
p, err := mode.Parse(options.Chmod)
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.

We call copierHandlerGetOne() for every item that we're reading. How expensive is this?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good question. I think the only way to avoid this would be to compute the result of mode.Parse before the calls to copierHandlerGetOne(), and pass it as an argument to the function. As it already takes a lot of arguments I don't love this, as it feels a bit ugly. I haven't benchmarked mode.Parse(), but it looks pretty efficient, exits out early if it just contains a numeric string, and obviously is only called if options.Chmod is set.

However I don't have strong feelings either way, if you think passing the result of mode.Parse() to copierHandlerGetOne() is preferable I'm happy to make the change to make that happen. Or if you have an alternative suggestion.

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.

Yeah, go ahead and initialize the mode.Set in the caller, and pass a pointer to it into copierHandlerGetOne() as an argument (probably with a more descriptive name, "chmod" as the Put handler calls it would be fine) so that it can be compared to nil where it's currently comparing options.Chmod to an empty string.

Comment thread copier/copier_test.go Outdated
Comment thread copier/copier_test.go Outdated
Comment thread copier/copier_test.go Outdated
@nalind nalind mentioned this pull request Apr 14, 2026
51 tasks
@nickjwhite
Copy link
Copy Markdown
Author

Thanks for the detailed review, @nalind! I'll fix these up tomorrow and push a fresh version.

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Apr 15, 2026
@nickjwhite
Copy link
Copy Markdown
Author

Thanks for the detailed review, @nalind! I'll fix these up tomorrow and push a fresh version.

I ended up not waiting 'til tomorrow and just doing it. Replaced a couple more if statements with assert.Equal while I was there, too.

I'm not sure what to do about the mode.Parse() call in copierHandlerGetOne(), I replied to your comment on that, happy to take your guidance on it.

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.

Please go ahead and make that change. I think we're going to want this to be rebased before merging.

Comment thread copier/copier.go Outdated
}
// force ownership and/or permissions, if requested
if options.Chmod != "" {
p, err := mode.Parse(options.Chmod)
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.

Yeah, go ahead and initialize the mode.Set in the caller, and pass a pointer to it into copierHandlerGetOne() as an argument (probably with a more descriptive name, "chmod" as the Put handler calls it would be fine) so that it can be compared to nil where it's currently comparing options.Chmod to an empty string.

Comment thread commit_test.go Outdated
@nickjwhite
Copy link
Copy Markdown
Author

Please go ahead and make that change. I think we're going to want this to be rebased before merging.

Done, including the rebase. I haven't tested as heavily, as the tests aren't all working on my local machine as they should, but I'll trust in the CI tests for now.

@nalind
Copy link
Copy Markdown
Member

nalind commented Apr 21, 2026

Done, including the rebase. I haven't tested as heavily, as the tests aren't all working on my local machine as they should, but I'll trust in the CI tests for now.

Changes look good, but usually I expect merge commits to be dropped during a rebase. Did you git fetch upstream; git rebase -i upstream/main, or use a different method?

@nickjwhite
Copy link
Copy Markdown
Author

Changes look good, but usually I expect merge commits to be dropped during a rebase. Did you git fetch upstream; git rebase -i upstream/main, or use a different method?

Oh, apologies, I said I rebased but I actually just merged main, indeed, my bad. I made a fresh branch from latest main, and cherry-picked & manually reapplied & amended my changes to it. So hopefully this is better.

Comment thread copier/copier.go Outdated
@nalind
Copy link
Copy Markdown
Member

nalind commented Apr 22, 2026

Much, better, thanks!

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.

LGTM

@nalind
Copy link
Copy Markdown
Member

nalind commented Apr 22, 2026

@containers/buildah-maintainers PTAL

@TomSweeneyRedHat
Copy link
Copy Markdown
Member

@nickjwhite looks like you may need to rebase this.

Comment thread tests/copy.bats
@TomSweeneyRedHat
Copy link
Copy Markdown
Member

Other than a few test tweaks, and a rebase
LGTM

This adds an optional Chmod string option to GetOptions and PutOptions.
If set, this overrides the ChmodDirs and ChmodFiles options. If unset,
they continue to work as before.

The --chmod option to buildah add and buildah copy works with symbolic
as well as numeric arguments.

Fixes containers#6066

Signed-off-by: Nick White <git@njw.name>
@nickjwhite
Copy link
Copy Markdown
Author

@TomSweeneyRedHat can you take another look please? I added the extra tests you suggested and rebased, so this should be ready to go.

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.

Containerfile --chmod +x not working in podman

3 participants