cp: better permissions mode handling with umask awareness #10904
+568
−141
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.
Fix #10787, #10862, Supersede #10859.
This PR reworks the permissions mode handling such that its behaviour is in line with GNU's implementation. Specifically:
set umask to !0o077, which means (1) cp can actually create and work with new directories/files which will have 700 permissions mode before their final calculated mode is set. the original umask is kept and passed around for calculation in the case of newly created and non-mode-preserving dir/files. umask is restored to original on exit.
for explicit non-mode-preserving, newly created dir/files, use 777 and 666 modes for calculation respectively.
for newly created dir/files, always set their permission mode to the correct one.
added 12 new tests for the combination of existing/not-existing, no-preserve/default/preserve, dir/file.