cp: apply the umask to directories created by cp -r - #14576
Open
nagendramohan wants to merge 1 commit into
Open
nagendramohan wants to merge 1 commit into
nagendramohan wants to merge 1 commit into
Conversation
|
GNU testsuite comparison: |
nagendramohan
force-pushed
the
fix/cp-recursive-dir-umask-14549
branch
from
September 15, 2026 09:39
85226a4 to
a1b323e
Compare
Devel08
reviewed
Sep 15, 2026
Without a preserve flag, cp -r gave every directory it created the source's mode unmasked, so a 777 source directory became 777 regardless of the umask, while regular files in the same copy were masked correctly. The final permission pass defaulted a freshly-created directory to preserving the source mode. Apply the umask in that defaulted case, as GNU does, while a real preserve (-p/-a) and --no-preserve=mode are unchanged. Fixes uutils#14549 Signed-off-by: nagendramohan <nagendramohan1990@gmail.com>
nagendramohan
force-pushed
the
fix/cp-recursive-dir-umask-14549
branch
from
September 16, 2026 02:43
f89e542 to
6e16f3a
Compare
sylvestre
reviewed
Sep 16, 2026
| // A created directory only defaults to copying the source mode; unlike an | ||
| // explicit preserve (-p/-a), GNU applies the umask to it. | ||
| let apply_umask_to_mode = | ||
| dest_is_freshly_created_dir && !matches!(attributes.mode, Preserve::Yes { .. }); |
Contributor
There was a problem hiding this comment.
why this variable ?
and at this position in the function?
This was referenced Sep 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Without a preserve flag, cp -r gave every directory it created the source's mode unmasked, so a 777 source directory became 777 regardless of the umask, while regular files in the same copy were masked correctly.
The final permission pass defaulted a freshly-created directory to preserving the source mode. Apply the umask in that defaulted case, as GNU does, while a real preserve (-p/-a) and --no-preserve=mode are unchanged.
Fixes #14549