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

cp: move symlink check to the right place

This commit is contained in:
Michael Debertol 2021-06-18 11:42:37 +02:00
parent 12a1c87cb8
commit 315bfd65a3

View file

@ -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() {