Repository navigation
cp: give --parents directories the source mode, leave an existing path alone - #15074
Merged
Merged
Conversation
|
GNU testsuite comparison: |
abendrothj
force-pushed
the
cp-parents-dir-mode
branch
from
October 5, 2026 09:28
3f583da to
773354f
Compare
sylvestre
reviewed
Oct 5, 2026
sylvestre
reviewed
Oct 5, 2026
sylvestre
reviewed
Oct 5, 2026
sylvestre
reviewed
Oct 5, 2026
sylvestre
reviewed
Oct 5, 2026
Contributor
Merging this PR will not alter performance
Comparing Footnotes
|
…h alone Without -p, the parent directories that --parents created got the default mode instead of the mode of the source directory they stand for, filtered through the umask. With -p/-a, attributes were copied onto every parent directory in the path even when all of them already existed in the destination. Create the missing parents owner-only while the copy runs. Once it is done, give the created ones the attributes of a freshly created directory, as cp -r does. As in GNU cp, -p/-a also refreshes the parents that already existed if any had to be created, and touches none of them otherwise. Nothing is created for a source that cannot be found, and --no-preserve=mode still creates them with the default mode. Closes uutils#15073
abendrothj
force-pushed
the
cp-parents-dir-mode
branch
from
October 7, 2026 11:28
2ee3a34 to
0238891
Compare
sylvestre
reviewed
Oct 7, 2026
The directories that --parents creates stay owner-only until the copy is done. If the copy stopped early, or realpath of a source ancestor failed because a directory above the working directory is not searchable, they kept that mode for good. Set their attributes however the copy ended, as GNU does, through "src/." when realpath fails, in one helper shared by file and directory operands.
abendrothj
force-pushed
the
cp-parents-dir-mode
branch
from
October 7, 2026 22:04
0238891 to
806cf8e
Compare
Contributor
|
Thanks for your PR |
Contributor
|
thanks! |
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.
Closes #15073
Without
-p, the parent directories that--parentscreated got the default mode, not the mode of the source directory they stand for filtered through the umask. With-p/-a, attributes were copied onto every parent directory in the path even when all of them already existed in the destination.The missing parents are now created owner-only while the copy runs. Afterwards the created ones get the attributes of a fresh directory, the same way
cp -rtreats directories it creates. As in GNU cp,-p/-aalso refreshes the parents that already existed when any had to be created, and leaves the path alone otherwise. Nothing is created for a source that can't be found, and--no-preserve=modestill gives the default mode. If the copy fails part-way, the created parents still get their final attributes. Both cases are fixed for file and directory operands.I checked 32 cases against GNU cp 9.12 (umask,
-p/-a/--no-preserve=mode, read-only/sticky/setgid source directories, partially and fully existing paths, failing sources) and the results are identical; main differed in 16. GNU'stests/cppasses locally (54 pass, 12 skipped: root, SELinux, ACL tools, valgrind, group setup).This overlaps part of #10904, which has been stalled since April.