From 345f224a9ce7029c86beae2e4ad9d1eea7c56432 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sat, 12 Aug 2023 11:47:46 +0200 Subject: Remove the cache directory after successful operation --- src/main.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index a6c77ef..233549d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -133,16 +133,17 @@ fn work() -> Result<(), io::Error> { .sorted_by_key(|s| Reverse(s.0.components().count())) .collect_vec(); + let mut cache_dir = PathBuf::default(); 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::(); + cache_dir = [Path::new(cache_base.as_str()), Path::new("mmv"), Path::new(pid.as_str())].iter().collect::(); fs::create_dir_all(&cache_dir)?; let cwd = require!(env::current_dir()); - require!(env::set_current_dir(cache_dir)); + require!(env::set_current_dir(&cache_dir)); backup_srcs(ps.iter().map(|(s, _, _)| s))?; require!(env::set_current_dir(cwd)); } @@ -160,6 +161,10 @@ fn work() -> Result<(), io::Error> { } } + if !flags.nobackup { + fs::remove_dir_all(cache_dir)?; + } + Ok(()) } -- cgit v1.2.3