Merge pull request #8747 from Anonymous-AAA/fix-recursive-cp-backslash

cp: fix recursive cp fails on files with trailing backslashes
This commit is contained in:
Alen Antony 2025-09-28 22:50:10 +05:30 committed by GitHub
parent 2e0e487749
commit 52c71dcac9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 1 deletions

View file

@ -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:\\")));
}

View file

@ -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\\"));
}