diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 7e7bcca4c..8f47adc28 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -895,14 +895,7 @@ fn copy_source( options: &Options, ) -> CopyResult<()> { let source_path = Path::new(&source); - // if no-dereference is enabled and this is a symlink, don't treat it as a directory - if source_path.is_dir() - && !(!options.dereference - && fs::symlink_metadata(source_path) - .unwrap() - .file_type() - .is_symlink()) - { + if source_path.is_dir() { // Copy as directory copy_directory(source, target, options) } else { @@ -943,6 +936,11 @@ fn copy_directory(root: &Path, target: &TargetSlice, options: &Options) -> CopyR return Err(format!("omitting directory '{}'", root.display()).into()); } + // if no-dereference is enabled and this is a symlink, copy it as a file + if !options.dereference && fs::symlink_metadata(root).unwrap().file_type().is_symlink() { + return copy_file(root, target, options); + } + let root_path = env::current_dir().unwrap().join(root); let root_parent = if target.exists() {