diff --git a/src/main.rs b/src/main.rs index abad215..20322c2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -221,8 +221,9 @@ fn get_time_from_file_name( /// # Params /// * `output_dir` - output directory containing /// * `keep` - number of backups to keep -fn remove_old_backups(output_dir: &PathBuf, keep: u64) -> Result<(), std::io::Error> { +fn remove_old_backups(output_dir: &PathBuf, keep: u64) -> Result { let mut backups = vec![]; + let mut num_of_removed_backups: usize = 0; for entry in output_dir.read_dir()? { let entry = entry?; @@ -242,15 +243,15 @@ fn remove_old_backups(output_dir: &PathBuf, keep: u64) -> Result<(), std::io::Er b_time.cmp(&a_time) }); - let number_to_remove = backups.len() - keep as usize; + num_of_removed_backups = backups.len() - keep as usize; - for _i in 0..number_to_remove { + for _i in 0..num_of_removed_backups { let oldest = backups.pop().unwrap(); remove_file(oldest.path())?; } } - Ok(()) + Ok(num_of_removed_backups) } /// Sends a webhook to Discord if its configured @@ -341,7 +342,15 @@ fn do_backup(cfg: AlbatrossConfig) -> Result<(), std::io::Error> { remove_dir_all(&tmp_dir)?; - remove_old_backups(&cfg.backup.output_dir, cfg.backup.backups_to_keep)?; + let backups_removed = remove_old_backups(&cfg.backup.output_dir, cfg.backup.backups_to_keep)?; + + if backups_removed > 0 { + let msg = format!( + "Albatross mistook {} of your old backup for a french fries and ate it!! SKRAWWWW", + backups_removed + ); + send_webhook(msg.as_str(), &cfg); + } let secs = timer.elapsed().as_secs(); send_webhook( @@ -375,6 +384,8 @@ fn main() { Err(e) => println!("Error doing backup: {}", e), _ => {} } + + println!("Backup complete"); } else { println!("No worlds specified to backed up!") }