Skip to content

Commit

Permalink
Hard link serve panic fix (#2210)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Raymi306 authored and Keats committed Dec 18, 2023
1 parent 448a941 commit 0a9bfa1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion components/utils/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))?;
Expand Down

0 comments on commit 0a9bfa1

Please sign in to comment.