Fix overwrite option for copying directories (#133)

This commit is contained in:
guidable0 2023-12-29 22:17:16 +02:00 committed by GitHub
parent 507d88e63e
commit 39d9557559
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -138,7 +138,16 @@ pub async fn copy(
let contents = get_contents_at(source.to_path_buf(), options).await?;
if options.overwrite {
fs::remove_dir_all(target).await?;
let (is_dir, is_file) = match fs::metadata(&target).await {
Ok(meta) => (meta.is_dir(), meta.is_file()),
Err(e) if e.kind() == ErrorKind::NotFound => (false, false),
Err(e) => return Err(e.into()),
};
if is_dir {
fs::remove_dir_all(target).await?;
} else if is_file {
fs::remove_file(target).await?;
}
}
// FUTURE: Write dirs / files concurrently