mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
cp: copy attributes after making subdir (#6884)
This commit is contained in:
parent
4e77b010ec
commit
49ae68d443
3 changed files with 146 additions and 17 deletions
|
@ -3365,6 +3365,29 @@ fn test_copy_dir_preserve_permissions() {
|
|||
assert_metadata_eq!(metadata1, metadata2);
|
||||
}
|
||||
|
||||
/// cp should preserve attributes of subdirectories when copying recursively.
|
||||
#[cfg(all(not(windows), not(target_os = "freebsd"), not(target_os = "openbsd")))]
|
||||
#[test]
|
||||
fn test_copy_dir_preserve_subdir_permissions() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
at.mkdir("a1");
|
||||
at.mkdir("a1/a2");
|
||||
// Use different permissions for a better test
|
||||
at.set_mode("a1/a2", 0o0555);
|
||||
at.set_mode("a1", 0o0777);
|
||||
|
||||
ucmd.args(&["-p", "-r", "a1", "b1"])
|
||||
.succeeds()
|
||||
.no_stderr()
|
||||
.no_stdout();
|
||||
|
||||
// Make sure everything is preserved
|
||||
assert!(at.dir_exists("b1"));
|
||||
assert!(at.dir_exists("b1/a2"));
|
||||
assert_metadata_eq!(at.metadata("a1"), at.metadata("b1"));
|
||||
assert_metadata_eq!(at.metadata("a1/a2"), at.metadata("b1/a2"));
|
||||
}
|
||||
|
||||
/// Test for preserving permissions when copying a directory, even in
|
||||
/// the face of an inaccessible file in that directory.
|
||||
#[cfg(all(not(windows), not(target_os = "freebsd"), not(target_os = "openbsd")))]
|
||||
|
@ -5616,7 +5639,7 @@ mod link_deref {
|
|||
// which could be problematic if we aim to preserve ownership or mode. For example, when
|
||||
// copying a directory, the destination directory could temporarily be setgid on some filesystems.
|
||||
// This temporary setgid status could grant access to other users who share the same group
|
||||
// ownership as the newly created directory.To mitigate this issue, when creating a directory we
|
||||
// ownership as the newly created directory. To mitigate this issue, when creating a directory we
|
||||
// disable these excessive permissions.
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue