From c3e13888d084461938def401ec27dea583ec1c85 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sun, 10 Sep 2017 19:23:12 +0100 Subject: [PATCH] Cleanup csl file on program close --- src/config/mod.rs | 8 ++++++++ src/main.rs | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index 029d655..0420e6d 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -3,6 +3,7 @@ use serde_yaml::Value; use std::path::PathBuf; use std::collections::HashMap; use utils::result_prefix; +use std::fs::remove_file; pub mod read; pub mod validate; @@ -45,3 +46,10 @@ pub fn get_config() -> Result { try!(result_prefix(validate::validate(config.clone()), "Config Validation Error".into())); return Ok(Config::new(config)); } + + +pub fn cleanup_config(config: Config) { + if config.references.is_some() { + remove_file(config.references.unwrap().csl).expect("Failed to remove file"); + } +} diff --git a/src/main.rs b/src/main.rs index a0e0de4..96315a2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -56,7 +56,8 @@ fn main() { match subcommand { "build" => { let config = get_config(args.clone()); - utils::ok_or_exit(build(config)); + utils::ok_or_exit(build(config.clone())); + config::cleanup_config(config); } cmd => { writeln!(io::stderr(), "Unknown command {}.", cmd).unwrap();