Skip to content

Commit

Permalink
Make symlink_or_hardlink_file remove dest
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisDenton authored and rami3l committed Sep 17, 2024
1 parent e3f9a14 commit d89f785
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
5 changes: 0 additions & 5 deletions src/utils/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,6 @@ fn symlink_junction_inner(target: &Path, junction: &Path) -> io::Result<()> {
}
}

pub(crate) fn hardlink(src: &Path, dest: &Path) -> io::Result<()> {
let _ = fs::remove_file(dest);
fs::hard_link(src, dest)
}

pub fn remove_dir(path: &Path) -> io::Result<()> {
if fs::symlink_metadata(path)?.file_type().is_symlink() {
#[cfg(windows)]
Expand Down
6 changes: 5 additions & 1 deletion src/utils/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,11 @@ where
})
}

/// Attempts to symlink a file, falling back to hard linking if that fails.
///
/// If `dest` already exists then it will be replaced.
pub(crate) fn symlink_or_hardlink_file(src: &Path, dest: &Path) -> Result<()> {
let _ = fs::remove_file(dest);
// The error is only used by macos
let Err(_err) = symlink_file(src, dest) else {
return Ok(());
Expand All @@ -332,7 +336,7 @@ pub(crate) fn symlink_or_hardlink_file(src: &Path, dest: &Path) -> Result<()> {
}

pub fn hardlink_file(src: &Path, dest: &Path) -> Result<()> {
raw::hardlink(src, dest).with_context(|| RustupError::LinkingFile {
fs::hard_link(src, dest).with_context(|| RustupError::LinkingFile {
src: PathBuf::from(src),
dest: PathBuf::from(dest),
})
Expand Down

0 comments on commit d89f785

Please sign in to comment.