From 72820bf48af0f6dd977e21b7004129b339904d34 Mon Sep 17 00:00:00 2001 From: Adrian Wannenmacher Date: Tue, 27 Jun 2023 23:30:19 +0200 Subject: [PATCH] use hard-linking or copying instead of renaming --- src/main.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index e8c59f3..b9dcd7c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -96,7 +96,17 @@ fn main() -> anyhow::Result<()> { } }) .and_then(|target| { - fs::rename(&res.file_name, target).context("failed to move cached result") + fs::hard_link(&res.file_name, &target) + .context("failed to hard-link result") // for same type as below + .or_else(|_| { + fs::copy(&res.file_name, &target) + .map(|_| ()) + .context("failed to copy result") + }) + .and_then(|_| { + fs::remove_file(&res.file_name) + .context("failed to delete cached result") + }) }); if let Err(err) = res {