diff --git a/components/utils/src/fs.rs b/components/utils/src/fs.rs index 8a53df14..c29edba6 100644 --- a/components/utils/src/fs.rs +++ b/components/utils/src/fs.rs @@ -86,7 +86,12 @@ pub fn copy_file_if_needed(src: &Path, dest: &Path, hard_link: bool) -> Result<( } if hard_link { - std::fs::hard_link(src, dest)? + if dest.exists() { + std::fs::remove_file(dest) + .with_context(|| format!("Error removing file: {:?}", dest))?; + } + std::fs::hard_link(src, dest) + .with_context(|| format!("Error hard linking file, src: {:?}, dst: {:?}", src, dest))?; } else { let src_metadata = metadata(src) .with_context(|| format!("Failed to get metadata of {}", src.display()))?;