Skip to content

Commit 0878925

Browse files
authored
chore: add test for setgid bit inheritance in mkdir -p (#10412)
1 parent 75b9ad4 commit 0878925

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

tests/by-util/test_mkdir.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,33 @@ fn test_mkdir_parent_mode_with_explicit_mode() {
908908
);
909909
}
910910

911+
/// Test that nested directories inherit the setgid bit with mkdir -p.
912+
#[test]
913+
#[cfg(target_os = "linux")]
914+
fn test_mkdir_parent_inherits_setgid() {
915+
let (at, mut ucmd) = at_and_ucmd!();
916+
917+
at.mkdir("parent");
918+
at.set_mode("parent", 0o2755);
919+
920+
ucmd.arg("-p")
921+
.arg("parent/child/grandchild")
922+
.succeeds()
923+
.no_stderr()
924+
.no_stdout();
925+
926+
// All descendants should inherit the setgid bit (0o2000)
927+
assert_eq!(at.metadata("parent").permissions().mode() & 0o2000, 0o2000);
928+
assert_eq!(
929+
at.metadata("parent/child").permissions().mode() & 0o2000,
930+
0o2000
931+
);
932+
assert_eq!(
933+
at.metadata("parent/child/grandchild").permissions().mode() & 0o2000,
934+
0o2000
935+
);
936+
}
937+
911938
#[test]
912939
fn test_mkdir_concurrent_creation() {
913940
// Test concurrent mkdir -p operations: 10 iterations, 8 threads, 40 levels nesting

0 commit comments

Comments
 (0)