From 93741fda7c94662b0cec15ea1d1906a81032e1f1 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 17 Sep 2021 09:18:38 +0200 Subject: Fix: Delete target path before copying file to it This fixes a bug: If the target file existed, but was created by another user, the tokio::fs::copy() function was not able to overwrite it (only to empty the file). So with this patch, we remove the file before we copy a new file to the target location. Signed-off-by: Matthias Beyer Tested-by: Matthias Beyer --- src/commands/release.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/commands/release.rs b/src/commands/release.rs index 460fbeb..50d3918 100644 --- a/src/commands/release.rs +++ b/src/commands/release.rs @@ -166,6 +166,13 @@ async fn new_release( } } + if dest_path.exists() { + debug!("Removing {} before writing new file to this path", dest_path.display()); + tokio::fs::remove_file(&dest_path) + .await + .with_context(|| anyhow!("Removing {} before writing new file to this path", dest_path.display()))?; + } + // else !dest_path.exists() tokio::fs::copy(&art_path, &dest_path) .await -- cgit v1.2.3