diff options
Diffstat (limited to 'src/database')
-rw-r--r-- | src/database/file/mod.rs | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/database/file/mod.rs b/src/database/file/mod.rs index 0336a80..53dea04 100644 --- a/src/database/file/mod.rs +++ b/src/database/file/mod.rs @@ -596,15 +596,19 @@ impl Storage for FileStorage { .open(&temppath) .await?; - let mut settings: HashMap<String, String> = { - let mut f = File::open(&path).await?; - let mut content = String::new(); - f.read_to_string(&mut content).await?; - if content.is_empty() { - HashMap::default() - } else { - serde_json::from_str(&content)? + let mut settings: HashMap<String, String> = match File::open(&path).await { + Ok(mut f) => { + let mut content = String::new(); + f.read_to_string(&mut content).await?; + if content.is_empty() { + HashMap::default() + } else { + serde_json::from_str(&content)? + } } + Err(err) => if err.kind() == IOErrorKind::NotFound { + HashMap::default() + } else { Err(err)? } }; settings.insert(setting, value); tempfile.write_all(serde_json::to_string(&settings)?.as_bytes()).await?; |