From f5ba3e3062f29880e854de990342b7832ca04318 Mon Sep 17 00:00:00 2001 From: Charles Hall Date: Tue, 8 Oct 2024 19:16:18 -0700 Subject: [PATCH] make each db backend responsible for its own setup RocksDB automatically creates parent directories already. SQLite doesn't create parent directories, only the db file if it didn't exist. --- src/database.rs | 11 ----------- src/database/abstraction/sqlite.rs | 3 +++ 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/database.rs b/src/database.rs index 2ce6eb7f..81abfddd 100644 --- a/src/database.rs +++ b/src/database.rs @@ -3,7 +3,6 @@ use std::{ fs, io::Write, mem::size_of, - path::Path, sync::Arc, }; @@ -241,16 +240,6 @@ impl KeyValueDatabase { "Compiled without support for any databases", )); - if !Path::new(&config.database.path).exists() { - fs::create_dir_all(&config.database.path).map_err(|_| { - Error::BadConfig( - "Database folder doesn't exists and couldn't be created \ - (e.g. due to missing permissions). Please create the \ - database folder yourself.", - ) - })?; - } - let x: Arc = match config.database.backend { #[cfg(feature = "sqlite")] DatabaseBackend::Sqlite => { diff --git a/src/database/abstraction/sqlite.rs b/src/database/abstraction/sqlite.rs index 943c553d..af24311f 100644 --- a/src/database/abstraction/sqlite.rs +++ b/src/database/abstraction/sqlite.rs @@ -1,5 +1,6 @@ use std::{ cell::RefCell, + fs, future::Future, path::{Path, PathBuf}, pin::Pin, @@ -67,6 +68,8 @@ pub(crate) struct Engine { impl Engine { pub(crate) fn open(config: &Config) -> Result { + fs::create_dir_all(&config.database.path)?; + let path = Path::new(&config.database.path).join("sqlite.db"); // calculates cache-size per permanent connection