delete dir if dir
This commit is contained in:
parent
7bd52b8a93
commit
c4097ae1a3
2 changed files with 11 additions and 3 deletions
|
@ -25,10 +25,14 @@ pub fn empty(dry: bool, days: Option<u32>) -> Result<(), Error> {
|
|||
println!("{:?}", file.path);
|
||||
} else {
|
||||
fs::remove_file(file.info_path)?;
|
||||
if file.deleted_path.is_dir() {
|
||||
fs::remove_dir_all(file.deleted_path)?;
|
||||
} else {
|
||||
fs::remove_file(file.deleted_path)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -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)?;
|
||||
|
|
Loading…
Reference in a new issue