Skip to content

Commit d9a2a9d

Browse files
committed
cp: add subdir permissions test
1 parent 1809c02 commit d9a2a9d

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

tests/by-util/test_cp.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3365,6 +3365,29 @@ fn test_copy_dir_preserve_permissions() {
33653365
assert_metadata_eq!(metadata1, metadata2);
33663366
}
33673367

3368+
/// cp should preserve attributes of subdirectories when copying recursively.
3369+
#[cfg(all(not(windows), not(target_os = "freebsd"), not(target_os = "openbsd")))]
3370+
#[test]
3371+
fn test_copy_dir_preserve_subdir_permissions() {
3372+
let (at, mut ucmd) = at_and_ucmd!();
3373+
at.mkdir("a1");
3374+
at.mkdir("a1/a2");
3375+
// Use different permissions for a better test
3376+
at.set_mode("a1/a2", 0o0555);
3377+
at.set_mode("a1", 0o0777);
3378+
3379+
ucmd.args(&["-p", "-r", "a1", "b1"])
3380+
.succeeds()
3381+
.no_stderr()
3382+
.no_stdout();
3383+
3384+
// Make sure everything is preserved
3385+
assert!(at.dir_exists("b1"));
3386+
assert!(at.dir_exists("b1/a2"));
3387+
assert_metadata_eq!(at.metadata("a1"), at.metadata("b1"));
3388+
assert_metadata_eq!(at.metadata("a1/a2"), at.metadata("b1/a2"));
3389+
}
3390+
33683391
/// Test for preserving permissions when copying a directory, even in
33693392
/// the face of an inaccessible file in that directory.
33703393
#[cfg(all(not(windows), not(target_os = "freebsd"), not(target_os = "openbsd")))]
@@ -5616,7 +5639,7 @@ mod link_deref {
56165639
// which could be problematic if we aim to preserve ownership or mode. For example, when
56175640
// copying a directory, the destination directory could temporarily be setgid on some filesystems.
56185641
// This temporary setgid status could grant access to other users who share the same group
5619-
// ownership as the newly created directory.To mitigate this issue, when creating a directory we
5642+
// ownership as the newly created directory. To mitigate this issue, when creating a directory we
56205643
// disable these excessive permissions.
56215644
#[test]
56225645
#[cfg(unix)]

0 commit comments

Comments
 (0)