mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2026-01-18 11:11:10 +00:00
Merge pull request #4074 from jfinkels/cp-force-dangling-symlink
cp: restrict copy through dangling symlink with -f
This commit is contained in:
commit
f60e861232
2 changed files with 24 additions and 5 deletions
|
|
@ -1270,10 +1270,6 @@ fn copy_file(
|
|||
return Ok(());
|
||||
}
|
||||
|
||||
if file_or_link_exists(dest) {
|
||||
handle_existing_dest(source, dest, options, source_in_command_line)?;
|
||||
}
|
||||
|
||||
// Fail if dest is a dangling symlink or a symlink this program created previously
|
||||
if dest.is_symlink() {
|
||||
if FileInformation::from_path(dest, false)
|
||||
|
|
@ -1287,7 +1283,13 @@ fn copy_file(
|
|||
)));
|
||||
}
|
||||
let copy_contents = options.dereference(source_in_command_line) || !source.is_symlink();
|
||||
if copy_contents && !dest.exists() {
|
||||
if copy_contents
|
||||
&& !dest.exists()
|
||||
&& !matches!(
|
||||
options.overwrite,
|
||||
OverwriteMode::Clobber(ClobberMode::RemoveDestination)
|
||||
)
|
||||
{
|
||||
return Err(Error::Error(format!(
|
||||
"not writing through dangling symlink '{}'",
|
||||
dest.display()
|
||||
|
|
@ -1295,6 +1297,10 @@ fn copy_file(
|
|||
}
|
||||
}
|
||||
|
||||
if file_or_link_exists(dest) {
|
||||
handle_existing_dest(source, dest, options, source_in_command_line)?;
|
||||
}
|
||||
|
||||
if options.verbose {
|
||||
println!("{}", context_for(source, dest));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue