From 9006aef87c1dd042dd140f71a09279e95f803227 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Sat, 30 Mar 2024 09:17:26 +0100 Subject: only copy non existing --- src/main.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 12c920d..f390f31 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,12 +7,16 @@ use walkdir::WalkDir; async fn copy(from: String, to: String) -> std::io::Result<()> { let from_path = std::path::Path::new(&from); let to_path = std::path::Path::new(&to); - if from_path.is_dir() { - std::fs::create_dir_all(to)?; - } else if from_path.is_file() { - std::fs::create_dir_all(to_path.parent().unwrap())?; - std::fs::copy(from, to)?; + + if !to_path.exists() { + if from_path.is_dir() { + std::fs::create_dir_all(to)?; + } else if from_path.is_file() { + std::fs::create_dir_all(to_path.parent().unwrap())?; + std::fs::copy(from, to)?; + } } + Ok(()) } -- cgit v1.2.3-70-g09d2