1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27:44 +00:00

cp: only get the current directory once

This commit is contained in:
Michael Debertol 2021-06-18 11:48:13 +02:00
parent 32526e3048
commit a371c03431

View file

@ -941,7 +941,10 @@ fn copy_directory(root: &Path, target: &TargetSlice, options: &Options) -> CopyR
return copy_file(root, target, options); return copy_file(root, target, options);
} }
let root_path = env::current_dir().unwrap().join(root); let current_dir =
env::current_dir().unwrap_or_else(|e| crash!(1, "failed to get current directory {}", e));
let root_path = current_dir.join(root);
let root_parent = if target.exists() { let root_parent = if target.exists() {
root_path.parent() root_path.parent()
@ -968,10 +971,7 @@ fn copy_directory(root: &Path, target: &TargetSlice, options: &Options) -> CopyR
{ {
let p = or_continue!(path); let p = or_continue!(path);
let is_symlink = fs::symlink_metadata(p.path())?.file_type().is_symlink(); let is_symlink = fs::symlink_metadata(p.path())?.file_type().is_symlink();
let path = match env::current_dir() { let path = current_dir.join(&p.path());
Ok(cwd) => cwd.join(&p.path()),
Err(e) => crash!(1, "failed to get current directory {}", e),
};
let local_to_root_parent = match root_parent { let local_to_root_parent = match root_parent {
Some(parent) => { Some(parent) => {