1
1
Fork 0
mirror of https://github.com/lune-org/lune.git synced 2025-04-13 15:00:53 +01:00

Use match

This commit is contained in:
guidable0 2023-12-29 16:52:12 +02:00
parent b75cc2a90d
commit 1d7e6ce71c
No known key found for this signature in database
GPG key ID: 197A7090DD478ECC

View file

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