aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-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(())
}