From e8aa36beb3ef9903c95bd1c84003efe1dcf0ac3d Mon Sep 17 00:00:00 2001 From: Lukas Bergdoll Date: Sun, 9 Sep 2018 12:13:28 +0200 Subject: [PATCH] Avoid overwriting existing config with --seed-config --- src/config.rs | 9 ++++++++- src/main.rs | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/config.rs b/src/config.rs index c9070eb..82bc135 100644 --- a/src/config.rs +++ b/src/config.rs @@ -208,10 +208,17 @@ pub fn make_default_syntax_config() -> Result { } } + let syntax_config_file_path = config_dir.join(SYNTAX_CONFIG_FILE_NAME); + if syntax_config_file_path.is_file() { + return Err(ConfigError(format!( + "A configuration file already exists at {}, no action was taken.", + syntax_config_file_path.to_str().unwrap() + ))); + } + let serialized_syntax_config = toml::to_string(&RawConfig::new()) .map_err(|err| ConfigError(format!("Failed to serialize default syntax config: {}", err)))?; - let syntax_config_file_path = config_dir.join(SYNTAX_CONFIG_FILE_NAME); let mut syntax_config_file = fs::File::create(&syntax_config_file_path) .map_err(map_io_err_to_config_err)?; let _wc = syntax_config_file.write(serialized_syntax_config.as_bytes()) diff --git a/src/main.rs b/src/main.rs index b34b5e8..748657e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -299,7 +299,7 @@ fn main() { process::exit(0); }, Err(ConfigError(msg)) => { - eprintln!("Could not look up syntax_config_path: {}", msg); + eprintln!("Could not create seed config: {}", msg); process::exit(1); }, Err(_) => {