Skip to content

Commit

Permalink
remove check for destination is link
Browse files Browse the repository at this point in the history
  • Loading branch information
cre4ture committed Jan 18, 2024
1 parent b08bcca commit b29bda3
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/uu/install/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,12 +748,17 @@ fn perform_backup(to: &Path, b: &Behavior) -> UResult<Option<PathBuf>> {
/// Returns an empty Result or an error in case of failure.
///
fn copy_file(from: &Path, to: &Path) -> UResult<()> {
let dest_meta_res = fs::symlink_metadata(to);
if let Ok(dest_meta) = dest_meta_res {
if dest_meta.is_symlink() {
// fs::copy fails if destination is a invalid symlink
// so lets just remove all symlinks at destination before copy
fs::remove_file(to)?;
// fs::copy fails if destination is a invalid symlink.
// so lets just remove all existing files at destination before copy.
match fs::remove_file(to) {
Ok(()) => {}
Err(e) if e.kind() == std::io::ErrorKind::NotFound => { /* expected */ }
Err(e) => {
show_error!(

Check warning on line 757 in src/uu/install/src/install.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/install/src/install.rs#L756-L757

Added lines #L756 - L757 were not covered by tests
"Failed to remove existing file {}. Error: {:?}",
to.display(),

Check warning on line 759 in src/uu/install/src/install.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/install/src/install.rs#L759

Added line #L759 was not covered by tests
e
);
}

Check warning on line 762 in src/uu/install/src/install.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/install/src/install.rs#L762

Added line #L762 was not covered by tests
}

Expand Down

0 comments on commit b29bda3

Please sign in to comment.