From 0a9bfa16c27a54af83adc109aa23f0a7c4cbfd12 Mon Sep 17 00:00:00 2001 From: Andrew Langmeier Date: Sat, 6 May 2023 10:02:29 -0400 Subject: [PATCH] Hard link serve panic fix (#2210) * Fix hard link panic and add better error info to std:fs errors * cargo fmt * Remove erroneously committed config change * Remove console import; Use with context to provide additional error info * improve error wording --- components/utils/src/fs.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/components/utils/src/fs.rs b/components/utils/src/fs.rs index 8a53df1480..c29edba689 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()))?;