feat: warn the user if they try to delete either ~ or /

This commit is contained in:
Muhammad Nauman Raza 2024-03-13 20:03:48 +00:00
parent 331a85ae0c
commit 1aa6d65752
Signed by: devraza
GPG key ID: 91EAD6081011574B

View file

@ -8,6 +8,9 @@ struct Args {
#[arg(short, long)]
recursive: bool,
#[arg(long)]
no_preserve_root: bool,
#[arg(trailing_var_arg = true, allow_hyphen_values = false)]
targets: Vec<String>,
}
@ -22,6 +25,13 @@ fn main() -> std::io::Result<()> {
}
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 fs::metadata(target).unwrap().is_dir() {
if args.recursive == false {