From 52c71dcac9e249d79e4f3486fa90b904ea246985 Mon Sep 17 00:00:00 2001 From: Alen Antony <77876851+Anonymous-AAA@users.noreply.github.com> Date: Sun, 28 Sep 2025 22:50:10 +0530 Subject: [PATCH] Merge pull request #8747 from Anonymous-AAA/fix-recursive-cp-backslash cp: fix recursive cp fails on files with trailing backslashes --- src/uucore/src/lib/features/fs.rs | 4 +++- tests/by-util/test_cp.rs | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/uucore/src/lib/features/fs.rs b/src/uucore/src/lib/features/fs.rs index e112bf730..f8d3c0f96 100644 --- a/src/uucore/src/lib/features/fs.rs +++ b/src/uucore/src/lib/features/fs.rs @@ -696,7 +696,7 @@ pub fn path_ends_with_terminator(path: &Path) -> bool { path.as_os_str() .as_bytes() .last() - .is_some_and(|&byte| byte == b'/' || byte == b'\\') + .is_some_and(|&byte| byte == b'/') } #[cfg(windows)] @@ -1053,6 +1053,7 @@ mod tests { assert!(path_ends_with_terminator(Path::new("/some/path/"))); // Path ends with a backslash + #[cfg(windows)] assert!(path_ends_with_terminator(Path::new("C:\\some\\path\\"))); // Path does not end with a terminator @@ -1064,6 +1065,7 @@ mod tests { // Root path assert!(path_ends_with_terminator(Path::new("/"))); + #[cfg(windows)] assert!(path_ends_with_terminator(Path::new("C:\\"))); } diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs index 563d127ff..618d789a8 100644 --- a/tests/by-util/test_cp.rs +++ b/tests/by-util/test_cp.rs @@ -7079,3 +7079,14 @@ fn test_cp_no_dereference_symlink_with_parents() { .succeeds(); assert_eq!(at.resolve_link("x/symlink-to-directory"), "directory"); } + +#[test] +#[cfg(unix)] +fn test_cp_recursive_files_ending_in_backslash() { + let ts = TestScenario::new(util_name!()); + let at = &ts.fixtures; + at.mkdir("a"); + at.touch("a/foo\\"); + ts.ucmd().args(&["-r", "a", "b"]).succeeds(); + assert!(at.file_exists("b/foo\\")); +}