Skip to content

Commit d89f785

Browse files
ChrisDentonrami3l
authored andcommitted
Make symlink_or_hardlink_file remove dest
1 parent e3f9a14 commit d89f785

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

src/utils/raw.rs

-5
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,6 @@ fn symlink_junction_inner(target: &Path, junction: &Path) -> io::Result<()> {
226226
}
227227
}
228228

229-
pub(crate) fn hardlink(src: &Path, dest: &Path) -> io::Result<()> {
230-
let _ = fs::remove_file(dest);
231-
fs::hard_link(src, dest)
232-
}
233-
234229
pub fn remove_dir(path: &Path) -> io::Result<()> {
235230
if fs::symlink_metadata(path)?.file_type().is_symlink() {
236231
#[cfg(windows)]

src/utils/utils.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,11 @@ where
312312
})
313313
}
314314

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

334338
pub fn hardlink_file(src: &Path, dest: &Path) -> Result<()> {
335-
raw::hardlink(src, dest).with_context(|| RustupError::LinkingFile {
339+
fs::hard_link(src, dest).with_context(|| RustupError::LinkingFile {
336340
src: PathBuf::from(src),
337341
dest: PathBuf::from(dest),
338342
})

0 commit comments

Comments
 (0)