feat: warn the user if they try to delete either ~ or /
This commit is contained in:
parent
331a85ae0c
commit
1aa6d65752
10
src/main.rs
10
src/main.rs
|
@ -8,6 +8,9 @@ struct Args {
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
recursive: bool,
|
recursive: bool,
|
||||||
|
|
||||||
|
#[arg(long)]
|
||||||
|
no_preserve_root: bool,
|
||||||
|
|
||||||
#[arg(trailing_var_arg = true, allow_hyphen_values = false)]
|
#[arg(trailing_var_arg = true, allow_hyphen_values = false)]
|
||||||
targets: Vec<String>,
|
targets: Vec<String>,
|
||||||
}
|
}
|
||||||
|
@ -22,6 +25,13 @@ fn main() -> std::io::Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
for target in args.targets.iter() {
|
for target in args.targets.iter() {
|
||||||
|
if args.no_preserve_root == false {
|
||||||
|
if target == "/" || target == "~" {
|
||||||
|
println!("{} you're trying to delete an important directory ({})! specify '--no-preserve-root' if you really want to do this", "error:".red().bold(), target);
|
||||||
|
process::exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if path::Path::new(target).exists() {
|
if path::Path::new(target).exists() {
|
||||||
if fs::metadata(target).unwrap().is_dir() {
|
if fs::metadata(target).unwrap().is_dir() {
|
||||||
if args.recursive == false {
|
if args.recursive == false {
|
||||||
|
|
Loading…
Reference in a new issue