aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2023-08-12 11:47:46 +0200
committerThomas Voss <mail@thomasvoss.com> 2023-08-12 11:47:46 +0200
commit345f224a9ce7029c86beae2e4ad9d1eea7c56432 (patch)
treee9bedc233e6c4cf4ce7c12a20c8c7ed7fcfba2e3
parentb4fed83b9e5a9c60d7c3f06ad8cbec8bf3cc2b8d (diff)
Remove the cache directory after successful operation
-rw-r--r--src/main.rs9
1 files 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::<PathBuf>();
+ 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));
+ 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(())
}