Skip to content

cp: give --parents directories the source mode, leave an existing path alone - #15074

Merged
sylvestre merged 2 commits into
uutils:mainfrom
abendrothj:cp-parents-dir-mode
Oct 9, 2026
Merged

sylvestre merged 2 commits into
uutils:mainfrom
abendrothj:cp-parents-dir-mode

Conversation

@abendrothj

@abendrothj abendrothj commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Closes #15073

Without -p, the parent directories that --parents created 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 -r treats directories it creates. As in GNU cp, -p/-a also 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=mode still 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's tests/cp passes locally (54 pass, 12 skipped: root, SELinux, ACL tools, valgrind, group setup).

This overlaps part of #10904, which has been stalled since April.

Copilot AI balanced review requested due to automatic review settings October 5, 2026 06:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

GNU test failed: tests/cp/cp-a-selinux. tests/cp/cp-a-selinux is passing on 'main'. Maybe you have to rebase?
GNU test failed: tests/cp/cp-parents. tests/cp/cp-parents is passing on 'main'. Maybe you have to rebase?
GNU test failed: tests/cp/parent-perm. tests/cp/parent-perm is passing on 'main'. Maybe you have to rebase?

@abendrothj
abendrothj force-pushed the cp-parents-dir-mode branch from 3f583da to 773354f Compare October 5, 2026 09:28
Copilot AI balanced review requested due to automatic review settings October 5, 2026 09:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@abendrothj abendrothj changed the title cp: give --parents directories the source mode, leave existing ones alone cp: give --parents directories the source mode, leave an existing path alone Oct 5, 2026
Comment thread src/uu/cp/src/copydir.rs Resolved
Comment thread src/uu/cp/src/cp.rs Resolved
Comment thread src/uu/cp/src/cp.rs Resolved
Comment thread src/uu/cp/src/cp.rs Resolved
Comment thread src/uu/cp/src/cp.rs Resolved
Copilot AI balanced review requested due to automatic review settings October 5, 2026 23:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@codspeed

codspeed Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 11 untouched benchmarks
⏩ 442 skipped benchmarks1


Comparing abendrothj:cp-parents-dir-mode (806cf8e) with main (8edf725)2

Open in CodSpeed

Footnotes

  1. 442 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on main (8460811) during the generation of this report, so 8edf725 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

…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
Copilot AI balanced review requested due to automatic review settings October 7, 2026 11:28
@abendrothj
abendrothj force-pushed the cp-parents-dir-mode branch from 2ee3a34 to 0238891 Compare October 7, 2026 11:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Comment thread src/uu/cp/src/copydir.rs Resolved
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
abendrothj force-pushed the cp-parents-dir-mode branch from 0238891 to 806cf8e Compare October 7, 2026 22:04
Copilot AI balanced review requested due to automatic review settings October 7, 2026 22:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@sylvestre
sylvestre merged commit 0995805 into uutils:main Oct 9, 2026
99 checks passed
@sylvestre

Copy link
Copy Markdown
Contributor

Thanks for your PR

@sylvestre

Copy link
Copy Markdown
Contributor

thanks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cp: --parents gives created parent directories the default mode and rewrites existing ones with -a

3 participants