Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix overwrite option for copying directories #133

Merged
merged 2 commits into from
Dec 29, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/lune/builtins/fs/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down