From b17bc4a449695a5f0763ab6d24c8e2714f96c449 Mon Sep 17 00:00:00 2001 From: Marko Korhonen Date: Tue, 21 Jan 2020 22:21:24 +0200 Subject: [PATCH] Do not overwrite with --copy-config --- src/config.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/config.rs b/src/config.rs index 6be1d43..0aa799d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -56,10 +56,17 @@ fn xdg_path() -> PathBuf { pub fn copy_config() { let path = xdg_path(); - match fs::write(&path, toml::to_string(&Config::default()).unwrap()) { - Ok(()) => println!("Default config saved to {}", path.display()), - Err(err) => eprintln!("Failed to write default config: {}", err), - }; + if !path.exists() { + match fs::write(&path, toml::to_string(&Config::default()).unwrap()) { + Ok(()) => println!("Default config saved to {}", path.display()), + Err(err) => eprintln!("Failed to write default config: {}", err), + }; + } else { + eprintln!( + "There is a file at {} already. Will not overwrite", + path.display() + ); + } } pub fn load_xdg() -> Config {