From f7179d65eef4f9d272d1b90f623e0aed14101d9c Mon Sep 17 00:00:00 2001 From: YoursFunny Date: Mon, 21 Sep 2026 17:42:56 +0800 Subject: [PATCH] refactor(db): open_store no longer creates the directory handlers::db_path already creates the DATA_DIR before it opens $DATA_DIR/task_queue.db, and every other caller (tests) passes a path whose parent exists, so the guard plus its one-caller rusqlite_error mapper were duplicated work. The doc now says which caller owns the directory. --- crates/xmedia-bot/src/db.rs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/crates/xmedia-bot/src/db.rs b/crates/xmedia-bot/src/db.rs index da7826f..a4e3bd5 100644 --- a/crates/xmedia-bot/src/db.rs +++ b/crates/xmedia-bot/src/db.rs @@ -135,13 +135,10 @@ pub fn open_db(path: &str) -> rusqlite::Result { /// Opens the shared DB file, runs the merged schema for all three tables and /// returns a pool for it. One call per process in production (the stores -/// share the returned pool); tests call it per tempdir. +/// share the returned pool); tests call it per tempdir. The file's directory +/// must exist already — [`crate::handlers::db_path`] is what creates it, and +/// it is the only caller that takes a path it did not get from a tempdir. pub fn open_store(path: &str) -> rusqlite::Result> { - if let Some(parent) = std::path::Path::new(path).parent() - && !parent.as_os_str().is_empty() - { - std::fs::create_dir_all(parent).map_err(rusqlite_error)?; - } let conn = open_db(path)?; schema_init(&conn)?; migrate(&conn)?; @@ -182,10 +179,6 @@ fn migrate(conn: &Connection) -> rusqlite::Result<()> { Ok(()) } -fn rusqlite_error(e: std::io::Error) -> rusqlite::Error { - rusqlite::Error::ToSqlConversionFailure(Box::new(e)) -} - /// Creates the `tasks`, `chat_state` and `link_cache` tables (idempotent). /// The three stores used to own their own schema; keeping it in one place /// means one initialization for the whole database file.