delete dir if dir

This commit is contained in:
Michael Zhang 2019-12-08 22:26:35 -06:00
parent 7bd52b8a93
commit c4097ae1a3
No known key found for this signature in database
GPG key ID: 5BAEFE5D04F0CE6C
2 changed files with 11 additions and 3 deletions

View file

@ -25,7 +25,11 @@ pub fn empty(dry: bool, days: Option<u32>) -> Result<(), Error> {
println!("{:?}", file.path);
} else {
fs::remove_file(file.info_path)?;
fs::remove_file(file.deleted_path)?;
if file.deleted_path.is_dir() {
fs::remove_dir_all(file.deleted_path)?;
} else {
fs::remove_file(file.deleted_path)?;
}
}
}
}

View file

@ -2,8 +2,8 @@ use std::env;
use std::fs;
use std::path::{Path, PathBuf};
use walkdir::WalkDir;
use anyhow::Error;
use walkdir::WalkDir;
pub fn into_absolute(path: impl AsRef<Path>) -> Result<PathBuf, Error> {
let path = path.as_ref();
@ -23,7 +23,11 @@ pub fn recursive_copy(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> Result<()
let src = src.as_ref();
let dst = dst.as_ref();
for entry in WalkDir::new(src).contents_first(false).follow_links(false).same_file_system(true) {
for entry in WalkDir::new(src)
.contents_first(false)
.follow_links(false)
.same_file_system(true)
{
let entry = entry?;
let path = entry.path();
let relative_path = path.strip_prefix(src)?;