about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2022-05-01 04:51:12 +0300
committerVika <vika@fireburn.ru>2022-05-01 04:51:12 +0300
commit0a62fe61acdb5dda4e28322ed96c074240bbdc44 (patch)
treee9eeef732e7942360dff98a14c82d5e627fecc53
parent122361795b3b1376c6ba03ed6b160e9b89da93d7 (diff)
downloadkittybox-0a62fe61acdb5dda4e28322ed96c074240bbdc44.tar.zst
FileStorage: fix writing settings on empty file
-rw-r--r--src/database/file/mod.rs20
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?;