Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions tests/by-util/test_mkdir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,33 @@ fn test_mkdir_parent_mode_with_explicit_mode() {
);
}

/// Test that nested directories inherit the setgid bit with mkdir -p.
#[test]
#[cfg(target_os = "linux")]
fn test_mkdir_parent_inherits_setgid() {
let (at, mut ucmd) = at_and_ucmd!();

at.mkdir("parent");
at.set_mode("parent", 0o2755);

ucmd.arg("-p")
.arg("parent/child/grandchild")
.succeeds()
.no_stderr()
.no_stdout();

// All descendants should inherit the setgid bit (0o2000)
assert_eq!(at.metadata("parent").permissions().mode() & 0o2000, 0o2000);
assert_eq!(
at.metadata("parent/child").permissions().mode() & 0o2000,
0o2000
);
assert_eq!(
at.metadata("parent/child/grandchild").permissions().mode() & 0o2000,
0o2000
);
}

#[test]
fn test_mkdir_concurrent_creation() {
// Test concurrent mkdir -p operations: 10 iterations, 8 threads, 40 levels nesting
Expand Down
Loading