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
This commit is contained in:
Andrew Langmeier 2023-05-06 10:02:29 -04:00 committed by Vincent Prouillet
parent 448a941f93
commit 0a9bfa16c2

View File

@ -86,7 +86,12 @@ pub fn copy_file_if_needed(src: &Path, dest: &Path, hard_link: bool) -> Result<(
} }
if hard_link { 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 { } else {
let src_metadata = metadata(src) let src_metadata = metadata(src)
.with_context(|| format!("Failed to get metadata of {}", src.display()))?; .with_context(|| format!("Failed to get metadata of {}", src.display()))?;