From 06ece7d79d181bbd58b51a25cbef8268a35ddf78 Mon Sep 17 00:00:00 2001 From: Muhammad Nauman Raza Date: Wed, 13 Mar 2024 20:03:48 +0000 Subject: [PATCH] feat: warn the user if they try to delete either ~ or / --- src/main.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 6d0364c..c16a895 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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, } @@ -20,8 +23,15 @@ fn main() -> std::io::Result<()> { println!("{} {}", "note:".cyan().bold(), "try 'vpr -h' for more information"); process::exit(0); } - + 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 {