瀏覽代碼

only create storage directory if needed

Falko Schindler 1 年之前
父節點
當前提交
3d5cef2d91
共有 1 個文件被更改,包括 5 次插入1 次删除
  1. 5 1
      nicegui/storage.py

+ 5 - 1
nicegui/storage.py

@@ -45,6 +45,11 @@ class PersistentDict(observables.ObservableDict):
         super().__init__(data, self.backup)
         super().__init__(data, self.backup)
 
 
     def backup(self) -> None:
     def backup(self) -> None:
+        if not self.filepath.exists():
+            if not self:
+                return
+            self.filepath.parent.mkdir(exist_ok=True)
+
         async def backup() -> None:
         async def backup() -> None:
             async with aiofiles.open(self.filepath, 'w') as f:
             async with aiofiles.open(self.filepath, 'w') as f:
                 await f.write(json.dumps(self))
                 await f.write(json.dumps(self))
@@ -70,7 +75,6 @@ class Storage:
 
 
     def __init__(self) -> None:
     def __init__(self) -> None:
         self.storage_dir = Path('.nicegui')
         self.storage_dir = Path('.nicegui')
-        self.storage_dir.mkdir(exist_ok=True)
         self._general = PersistentDict(self.storage_dir / 'storage_general.json')
         self._general = PersistentDict(self.storage_dir / 'storage_general.json')
         self._users: Dict[str, PersistentDict] = {}
         self._users: Dict[str, PersistentDict] = {}