Skip to content

Commit ab65ebd

Browse files
authored
Merge pull request #8366 from julian-klode/trailing-dot-and-slash
install, mkdir: Handle dir/./ like dir/.
2 parents a1a2734 + abb5300 commit ab65ebd

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

src/uucore/src/lib/features/fs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,12 +534,12 @@ pub fn display_permissions_unix(mode: mode_t, display_file_type: bool) -> String
534534
result
535535
}
536536

537-
/// For some programs like install or mkdir, dir/. can be provided
537+
/// For some programs like install or mkdir, dir/. or dir/./ can be provided
538538
/// Special case to match GNU's behavior:
539-
/// install -d foo/. should work and just create foo/
539+
/// install -d foo/. (and foo/./) should work and just create foo/
540540
/// std::fs::create_dir("foo/."); fails in pure Rust
541541
pub fn dir_strip_dot_for_creation(path: &Path) -> PathBuf {
542-
if path.to_string_lossy().ends_with("/.") {
542+
if path.to_string_lossy().ends_with("/.") || path.to_string_lossy().ends_with("/./") {
543543
// Do a simple dance to strip the "/."
544544
Path::new(&path).components().collect::<PathBuf>()
545545
} else {

tests/by-util/test_install.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,6 +1518,13 @@ fn test_install_dir_dot() {
15181518
.arg("-v")
15191519
.succeeds()
15201520
.stdout_contains("creating directory 'dir5/cali'");
1521+
scene
1522+
.ucmd()
1523+
.arg("-d")
1524+
.arg("dir6/./")
1525+
.arg("-v")
1526+
.succeeds()
1527+
.stdout_contains("creating directory 'dir6'");
15211528

15221529
let at = &scene.fixtures;
15231530

@@ -1526,6 +1533,7 @@ fn test_install_dir_dot() {
15261533
assert!(at.dir_exists("dir3"));
15271534
assert!(at.dir_exists("dir4/cal"));
15281535
assert!(at.dir_exists("dir5/cali"));
1536+
assert!(at.dir_exists("dir6"));
15291537
}
15301538

15311539
#[test]

tests/by-util/test_mkdir.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,22 @@ fn test_mkdir_trailing_dot() {
332332
println!("ls dest {}", result.stdout_str());
333333
}
334334

335+
#[test]
336+
fn test_mkdir_trailing_dot_and_slash() {
337+
new_ucmd!().arg("-p").arg("-v").arg("test_dir").succeeds();
338+
339+
new_ucmd!()
340+
.arg("-p")
341+
.arg("-v")
342+
.arg("test_dir_a/./")
343+
.succeeds()
344+
.stdout_contains("created directory 'test_dir_a'");
345+
346+
let scene = TestScenario::new("ls");
347+
let result = scene.ucmd().arg("-al").run();
348+
println!("ls dest {}", result.stdout_str());
349+
}
350+
335351
#[test]
336352
#[cfg(not(windows))]
337353
fn test_umask_compliance() {

0 commit comments

Comments
 (0)