Skip to content

Commit 7e12383

Browse files
cp: show relative path of source file with -vr (#8887)
* cp: show relative path of source file with -vr Add test to cover fix. * fix test expected output for windows
1 parent ffbcb4b commit 7e12383

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

src/uu/cp/src/copydir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ fn copy_direntry(
296296
if !source_is_dir {
297297
if let Err(err) = copy_file(
298298
progress_bar,
299-
&entry.source_absolute,
299+
&entry.source_relative,
300300
entry.local_to_target.as_path(),
301301
options,
302302
symlinked_files,

tests/by-util/test_cp.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7136,3 +7136,30 @@ fn test_cp_no_preserve_target_directory() {
71367136
assert!(at.file_exists("e/f2"));
71377137
assert!(at.file_exists("e/f3"));
71387138
}
7139+
7140+
#[test]
7141+
fn test_cp_recurse_verbose_output() {
7142+
let source_dir = "source_dir";
7143+
let target_dir = "target_dir";
7144+
let file = "file";
7145+
#[cfg(not(windows))]
7146+
let output = format!(
7147+
"'{source_dir}' -> '{target_dir}/'\n'{source_dir}/{file}' -> '{target_dir}/{file}'\n"
7148+
);
7149+
#[cfg(windows)]
7150+
let output = format!(
7151+
"'{source_dir}' -> '{target_dir}\\'\n'{source_dir}\\{file}' -> '{target_dir}\\{file}'\n"
7152+
);
7153+
let (at, mut ucmd) = at_and_ucmd!();
7154+
7155+
at.mkdir(source_dir);
7156+
at.touch(format!("{source_dir}/{file}"));
7157+
7158+
ucmd.arg(source_dir)
7159+
.arg(target_dir)
7160+
.arg("-r")
7161+
.arg("--verbose")
7162+
.succeeds()
7163+
.no_stderr()
7164+
.stdout_is(output);
7165+
}

0 commit comments

Comments
 (0)