Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions src/uucore/src/lib/features/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,12 +534,12 @@ pub fn display_permissions_unix(mode: mode_t, display_file_type: bool) -> String
result
}

/// For some programs like install or mkdir, dir/. can be provided
/// For some programs like install or mkdir, dir/. or dir/./ can be provided
/// Special case to match GNU's behavior:
/// install -d foo/. should work and just create foo/
/// install -d foo/. (and foo/./) should work and just create foo/
/// std::fs::create_dir("foo/."); fails in pure Rust
pub fn dir_strip_dot_for_creation(path: &Path) -> PathBuf {
if path.to_string_lossy().ends_with("/.") {
if path.to_string_lossy().ends_with("/.") || path.to_string_lossy().ends_with("/./") {
// Do a simple dance to strip the "/."
Path::new(&path).components().collect::<PathBuf>()
} else {
Expand Down
8 changes: 8 additions & 0 deletions tests/by-util/test_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1518,6 +1518,13 @@ fn test_install_dir_dot() {
.arg("-v")
.succeeds()
.stdout_contains("creating directory 'dir5/cali'");
scene
.ucmd()
.arg("-d")
.arg("dir6/./")
.arg("-v")
.succeeds()
.stdout_contains("creating directory 'dir6'");

let at = &scene.fixtures;

Expand All @@ -1526,6 +1533,7 @@ fn test_install_dir_dot() {
assert!(at.dir_exists("dir3"));
assert!(at.dir_exists("dir4/cal"));
assert!(at.dir_exists("dir5/cali"));
assert!(at.dir_exists("dir6"));
}

#[test]
Expand Down
16 changes: 16 additions & 0 deletions tests/by-util/test_mkdir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,22 @@ fn test_mkdir_trailing_dot() {
println!("ls dest {}", result.stdout_str());
}

#[test]
fn test_mkdir_trailing_dot_and_slash() {
new_ucmd!().arg("-p").arg("-v").arg("test_dir").succeeds();

new_ucmd!()
.arg("-p")
.arg("-v")
.arg("test_dir_a/./")
.succeeds()
.stdout_contains("created directory 'test_dir_a'");

let scene = TestScenario::new("ls");
let result = scene.ucmd().arg("-al").run();
println!("ls dest {}", result.stdout_str());
}

#[test]
#[cfg(not(windows))]
fn test_umask_compliance() {
Expand Down
Loading