diff --git a/src/db/filesystem.rs b/src/db/filesystem.rs index 2cdb435..9074822 100644 --- a/src/db/filesystem.rs +++ b/src/db/filesystem.rs @@ -47,6 +47,22 @@ pub struct FilesystemDatabase { impl FilesystemDatabase { pub async fn from_path(path: impl AsRef) -> Result { let path = path.as_ref(); + + if !tokio::fs::try_exists(path) + .await + .map_err(|e| Box::new(FilesystemDatabaseError::ReadFileIO(path.to_path_buf(), e)))? + { + // The database doesn't exist yet, we create an empty one and try to write it + // to make sure the permissions are correct and the destination folder exists. + let mut db = Self { + inner: MemoryDatabase::default(), + path: path.to_path_buf(), + }; + + db.save().await?; + return Ok(Database::new(db)); + } + let s = tokio::fs::read(path) .await .map_err(|e| Box::new(FilesystemDatabaseError::ReadFileIO(path.to_path_buf(), e)))?;