Skip to content

Commit

Permalink
Fix overwrite option for copying directories (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
bloeo authored Dec 29, 2023
1 parent 507d88e commit 39d9557
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/lune/builtins/fs/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 39d9557

Please sign in to comment.