diff options
author | Thomas Voss <mail@thomasvoss.com> | 2023-08-12 11:44:14 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2023-08-12 11:44:14 +0200 |
commit | b4fed83b9e5a9c60d7c3f06ad8cbec8bf3cc2b8d (patch) | |
tree | c325da15c0afd0143d402faecc020587eee217f8 /src/main.rs | |
parent | 162a7ce1f86291d39f3ab2ef8866adeb6439d612 (diff) |
Add the -n option
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/main.rs b/src/main.rs index 278e530..a6c77ef 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,6 +23,7 @@ struct Flags { pub dryrun: bool, pub encode: bool, pub individual: bool, + pub nobackup: bool, pub nul: bool, pub verbose: bool, } @@ -41,6 +42,7 @@ impl Flags { Short('d') | Long("dryrun") => flags.dryrun = true, Short('e') | Long("encode") => flags.encode = true, Short('i') | Long("individual") => flags.individual = true, + Short('n') | Long("no-backup") => flags.nobackup = true, Short('v') | Long("verbose") => flags.verbose = true, Value(v) => { rest.push(v); @@ -59,7 +61,7 @@ fn usage(bad_flags: Option<lexopt::Error>) -> ! { if let Some(e) = bad_flags { warn!("{e}"); } - eprintln!("Usage: {p} [-0deiv] command [argument ...]"); + eprintln!("Usage: {p} [-0deinv] command [argument ...]"); process::exit(1); } @@ -131,17 +133,19 @@ fn work() -> Result<(), io::Error> { .sorted_by_key(|s| Reverse(s.0.components().count())) .collect_vec(); - let pid = process::id().to_string(); - let cache_base = env::var("XDG_CACHE_HOME").unwrap_or_else(|_| { - err!("XDG_CACHE_HOME variable must be set"); - }); - let cache_dir = [Path::new(cache_base.as_str()), Path::new("mmv"), Path::new(pid.as_str())].iter().collect::<PathBuf>(); - fs::create_dir_all(&cache_dir)?; + if !flags.nobackup { + let pid = process::id().to_string(); + let cache_base = env::var("XDG_CACHE_HOME").unwrap_or_else(|_| { + err!("XDG_CACHE_HOME variable must be set"); + }); + let cache_dir = [Path::new(cache_base.as_str()), Path::new("mmv"), Path::new(pid.as_str())].iter().collect::<PathBuf>(); + fs::create_dir_all(&cache_dir)?; - let cwd = require!(env::current_dir()); - require!(env::set_current_dir(cache_dir)); - backup_srcs(ps.iter().map(|(s, _, _)| s))?; - require!(env::set_current_dir(cwd)); + let cwd = require!(env::current_dir()); + require!(env::set_current_dir(cache_dir)); + backup_srcs(ps.iter().map(|(s, _, _)| s))?; + require!(env::set_current_dir(cwd)); + } if flags.dryrun { for (s, _, d) in ps { |