WIP: fix borrow

This commit is contained in:
cw 2020-09-22 17:28:30 +08:00
parent e91549d1e8
commit 0f6276e722
1 changed files with 14 additions and 5 deletions

View File

@ -152,7 +152,7 @@ impl Config {
let root_dir = fs.root_dir(); let root_dir = fs.root_dir();
match root_dir.create_file("/CONFIG.TXT") { match root_dir.create_file("/CONFIG.TXT") {
Ok(file) => { Ok(mut file) => {
file.truncate()?; file.truncate()?;
}, },
Err(e) => { Err(e) => {
@ -230,6 +230,9 @@ impl Config {
Ok(()) Ok(())
} }
pub fn write_str<'b>(&mut self, key: &str, data: &str) -> Result<'b, ()>{ pub fn write_str<'b>(&mut self, key: &str, data: &str) -> Result<'b, ()>{
let call_remove_config_key_bin = false;
let call_remove_config_txt = false;
if let Some(fs) = &self.fs { if let Some(fs) = &self.fs {
let root_dir = fs.root_dir(); let root_dir = fs.root_dir();
@ -254,7 +257,7 @@ impl Config {
file.seek(SeekFrom::End(0))?; file.seek(SeekFrom::End(0))?;
file.write_all(&["\n", key, "=", data, "\n"].concat().as_bytes())?; file.write_all(&["\n", key, "=", data, "\n"].concat().as_bytes())?;
self.remove_config_key_bin(key)?; call_remove_config_key_bin = true;
} else { } else {
root_dir.create_dir("/CONFIG")?; root_dir.create_dir("/CONFIG")?;
match root_dir.create_file(config_key_bin) { match root_dir.create_file(config_key_bin) {
@ -267,12 +270,18 @@ impl Config {
} }
}; };
self.remove_config_txt(key)?; call_remove_config_txt = true;
} }
Ok(())
} else { } else {
Err(Error::NoConfig) Err(Error::NoConfig)
} }
if call_remove_config_key_bin {
self.remove_config_key_bin(key)?;
}
if call_remove_config_txt {
self.remove_config_txt(key)?;
}
Ok(())
} }
} }