Skip to content

cp: apply the umask to directories created by cp -r - #14576

Open
nagendramohan wants to merge 2 commits into
uutils:mainfrom
nagendramohan:fix/cp-recursive-dir-umask-14549
Open

nagendramohan wants to merge 2 commits into
uutils:mainfrom
nagendramohan:fix/cp-recursive-dir-umask-14549

Conversation

@nagendramohan

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Sep 15, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/cut/bounded-memory (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/date/date-locale-hour (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/tail-n0f (fails in this run but passes in the 'main' branch)
Note: The gnu test tests/tail/pipe-f is now being skipped but was previously passing.
Congrats! The gnu test tests/seq/seq-epipe is now passing!

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
nagendramohan force-pushed the fix/cp-recursive-dir-umask-14549 branch from 85226a4 to a1b323e Compare September 15, 2026 09:39
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 -r creates directories with the source's mode, ignoring the umask

1 participant