From 905e4562272046d912f42f05973f48ca5ca02fd7 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 17 Sep 2021 09:18:26 +0200 Subject: Fix: Add more error context if release copy procedure fails Signed-off-by: Matthias Beyer --- src/commands/release.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/commands/release.rs b/src/commands/release.rs index 6f0232b..460fbeb 100644 --- a/src/commands/release.rs +++ b/src/commands/release.rs @@ -14,6 +14,7 @@ use std::io::Write; use std::path::PathBuf; use anyhow::anyhow; +use anyhow::Context; use anyhow::Error; use anyhow::Result; use clap::ArgMatches; @@ -166,8 +167,9 @@ async fn new_release( } // else !dest_path.exists() - tokio::fs::copy(art_path, &dest_path) + tokio::fs::copy(&art_path, &dest_path) .await + .with_context(|| anyhow!("Copying {} to {}", art_path.display(), dest_path.display())) .map_err(Error::from) .map(|_| (art, dest_path)) } -- cgit v1.2.3 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