Skip to content

Commit 11562c7

Browse files
committed
remove check for destination is link
1 parent 3413a8a commit 11562c7

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/uu/install/src/install.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -748,12 +748,17 @@ fn perform_backup(to: &Path, b: &Behavior) -> UResult<Option<PathBuf>> {
748748
/// Returns an empty Result or an error in case of failure.
749749
///
750750
fn copy_file(from: &Path, to: &Path) -> UResult<()> {
751-
let dest_meta_res = fs::symlink_metadata(to);
752-
if let Ok(dest_meta) = dest_meta_res {
753-
if dest_meta.is_symlink() {
754-
// fs::copy fails if destination is a invalid symlink
755-
// so lets just remove all symlinks at destination before copy
756-
fs::remove_file(to)?;
751+
// fs::copy fails if destination is a invalid symlink.
752+
// so lets just remove all existing files at destination before copy.
753+
match fs::remove_file(to) {
754+
Ok(()) => {}
755+
Err(e) if e.kind() == std::io::ErrorKind::NotFound => { /* expected */ }
756+
Err(e) => {
757+
show_error!(
758+
"Failed to remove existing file {}. Error: {:?}",
759+
to.display(),
760+
e
761+
);
757762
}
758763
}
759764

0 commit comments

Comments
 (0)