From e72b990ea293e16cbcf381dea7cc6af0eecdfc90 Mon Sep 17 00:00:00 2001 From: dbr Date: Tue, 15 Jun 2021 20:01:47 +1000 Subject: [PATCH] Avoid error if DB folder does not exist --- taskchampion/src/storage/sqlite.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/taskchampion/src/storage/sqlite.rs b/taskchampion/src/storage/sqlite.rs index 91eaf1f8a..e517b4b00 100644 --- a/taskchampion/src/storage/sqlite.rs +++ b/taskchampion/src/storage/sqlite.rs @@ -77,9 +77,14 @@ pub struct SqliteStorage { impl SqliteStorage { pub fn new>(directory: P) -> anyhow::Result { + // Ensure parent folder exists + std::fs::create_dir_all(&directory)?; + + // Open (or create) database let db_file = directory.as_ref().join("taskchampion.sqlite3"); let con = Connection::open(db_file)?; + // Initialize database let queries = vec![ "CREATE TABLE IF NOT EXISTS operations (id INTEGER PRIMARY KEY AUTOINCREMENT, data STRING);", "CREATE TABLE IF NOT EXISTS sync_meta (key STRING PRIMARY KEY, value STRING);",