From 4a0cbf3ba56d2f530a5805e5f63222d778899949 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 8 Feb 2025 20:06:09 -0500 Subject: [PATCH] Do not copy a file if it already exists. --- src/context/dependency.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/context/dependency.rs b/src/context/dependency.rs index aa4aab7..e79063f 100644 --- a/src/context/dependency.rs +++ b/src/context/dependency.rs @@ -27,8 +27,17 @@ impl Dependency { .ok_or("Output file should have a containing directory.")?, ) .await?; - // TODO: If file already exists, either error out or compare hash to avoid duplicate write. - tokio::fs::copy(absolute_path, path_to_output).await?; + + if tokio::fs::metadata(&path_to_output).await.is_ok() { + // TODO: compare hash and error out if they do not match. + println!( + "Not copying {} to {} because the output file already exists.", + absolute_path.display(), + path_to_output.display() + ); + } else { + tokio::fs::copy(absolute_path, path_to_output).await?; + } Ok(()) } }