added safety for overwriting configs

This commit is contained in:
JOLIMAITRE Matthieu 2022-10-05 01:52:39 +02:00
parent de3974725a
commit 5a7e5fae94
2 changed files with 10 additions and 2 deletions

View file

@ -1,12 +1,13 @@
use std::{
env, fs,
io::stdin,
path::{Path, PathBuf},
};
use ron::ser::PrettyConfig;
use serde::{Deserialize, Serialize};
use crate::utils::{log_success, Apply};
use crate::utils::{log_process, log_success, Apply};
#[derive(Debug, Serialize, Deserialize)]
pub struct Config {
@ -33,6 +34,11 @@ impl Config {
path.extend([Self::CONFIG_FILE_NAME]);
let content =
ron::ser::to_string_pretty(self, PrettyConfig::default().struct_names(true)).unwrap();
if path.exists() {
log_process("config already exists, overwrite it?");
let mut buff = String::new();
stdin().read_line(&mut buff).unwrap();
}
fs::write(path, content).unwrap();
}

View file

@ -89,6 +89,7 @@ fn compilation_args() -> Vec<String> {
"-Wall".to_string(),
"-Wextra".to_string(),
"-std=c99".to_string(),
"-pedantic".to_string(),
];
if Config::get_local_or_default().strict_mode() {
args.push("-Werror".to_string());
@ -138,7 +139,8 @@ fn main() {
} => {
let path =
path.unwrap_or_else(|| env::current_dir().unwrap().to_str().unwrap().to_string());
config::create(path.clone(), prefix);
let prefix = prefix.trim().trim_end_matches('*');
config::create(path.clone(), prefix.to_string());
if tests {
config::create_test(path);
}