cp -r <directory> -T <target> throws a StripPrefixError
Description:
Recursively copying a directory with the --no-target-directory (-T) option to another location with a different name throws a StripPrefixError
Steps to Reproduce:
-
Create a directory (i.e named
temp) -
Copy the created directory and give it a new name with the following command
cp -r temp -T new_temp
Expected Behavior:
A new directory should be created at the target location containing the same files as the original one
Actual Behavior:
The command throws the following error:
cp: StripPrefixError(StripPrefixError(()))
Environment:
OS: Void Linux
cp version: cp 0.0.30
This is triggered by this last line:
https://github.com/uutils/coreutils/blob/7e26f790520219e173f7be427d5065e0e2a2804a/src/uu/cp/src/copydir.rs#L179-L188
descendant is "" and context.root is "temp"
I need to understand what get_local_to_root_parent, should be doing, but that may help find the error there.
EDIT: no, this is completely wrong, ignore.
~~Could it be the following ?~~
impl<'a> Context<'a> {
fn new(root: &'a Path, target: &'a Path) -> std::io::Result<Self> {
let current_dir = env::current_dir()?;
let root_path = current_dir.join(root);
- let root_parent = if target.exists() && !root.to_str().unwrap().ends_with("/.") {
+ let root_parent = if root.exists() && !root.to_str().unwrap().ends_with("/.") {
root_path.parent().map(|p| p.to_path_buf())
} else {
Some(root_path)
};
Ok(Self {
current_dir,
root_parent,
target,
root,
})
}
}
~~it seems weird to look at whether target exists to compute the root parent, and explain why @EnumuratedDev issue appears only if new_temp does not exists ?~~
#7457 creates a failing test for this case.
Could you try #7465 ?