Check that target exists before trying removing it

This commit is contained in:
guidable0 2023-12-06 18:08:05 +02:00
parent 507d88e63e
commit b75cc2a90d
No known key found for this signature in database
GPG key ID: 197A7090DD478ECC

View file

@ -137,8 +137,13 @@ pub async fn copy(
} else if is_dir {
let contents = get_contents_at(source.to_path_buf(), options).await?;
if options.overwrite {
fs::remove_dir_all(target).await?;
if options.overwrite && target.exists() {
let metadata = fs::metadata(target).await?;
if metadata.is_file() {
fs::remove_file(target).await?;
} else if metadata.is_dir() {
fs::remove_dir_all(target).await?;
}
}
// FUTURE: Write dirs / files concurrently