Skip to content

Commit 52c71dc

Browse files
Merge pull request #8747 from Anonymous-AAA/fix-recursive-cp-backslash
cp: fix recursive cp fails on files with trailing backslashes
1 parent 2e0e487 commit 52c71dc

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ pub fn path_ends_with_terminator(path: &Path) -> bool {
696696
path.as_os_str()
697697
.as_bytes()
698698
.last()
699-
.is_some_and(|&byte| byte == b'/' || byte == b'\\')
699+
.is_some_and(|&byte| byte == b'/')
700700
}
701701

702702
#[cfg(windows)]
@@ -1053,6 +1053,7 @@ mod tests {
10531053
assert!(path_ends_with_terminator(Path::new("/some/path/")));
10541054

10551055
// Path ends with a backslash
1056+
#[cfg(windows)]
10561057
assert!(path_ends_with_terminator(Path::new("C:\\some\\path\\")));
10571058

10581059
// Path does not end with a terminator
@@ -1064,6 +1065,7 @@ mod tests {
10641065

10651066
// Root path
10661067
assert!(path_ends_with_terminator(Path::new("/")));
1068+
#[cfg(windows)]
10671069
assert!(path_ends_with_terminator(Path::new("C:\\")));
10681070
}
10691071

‎tests/by-util/test_cp.rs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7079,3 +7079,14 @@ fn test_cp_no_dereference_symlink_with_parents() {
70797079
.succeeds();
70807080
assert_eq!(at.resolve_link("x/symlink-to-directory"), "directory");
70817081
}
7082+
7083+
#[test]
7084+
#[cfg(unix)]
7085+
fn test_cp_recursive_files_ending_in_backslash() {
7086+
let ts = TestScenario::new(util_name!());
7087+
let at = &ts.fixtures;
7088+
at.mkdir("a");
7089+
at.touch("a/foo\\");
7090+
ts.ucmd().args(&["-r", "a", "b"]).succeeds();
7091+
assert!(at.file_exists("b/foo\\"));
7092+
}

0 commit comments

Comments
 (0)