From 05f513735e5608360ebe14f2a5e0ddc8b6911cda Mon Sep 17 00:00:00 2001 From: sreedev Date: Mon, 9 Jan 2023 11:01:52 -0500 Subject: [PATCH] tempdir fixes --- src/database.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/database.rs b/src/database.rs index 2982a4e..ef6d565 100644 --- a/src/database.rs +++ b/src/database.rs @@ -8,16 +8,18 @@ pub struct File { pub hash: String, } +fn db_connection_url(args: &Params) -> String { + match args.nocache { + true => String::from(":memory:"), + false => { + let temp_dir_path = temp_dir(); + format!("{}/deduplicator.db", temp_dir_path.display()) + } + } +} + pub fn get_connection(args: &Params) -> Result { - let mut tmp_file = temp_dir(); - tmp_file.push("deduplicator.db"); - - let connection_url = match args.nocache { - false => tmp_file.to_str().unwrap(), - true => ":memory:", - }; - - sqlite::open(connection_url).and_then(|conn| { + sqlite::open(db_connection_url(args)).and_then(|conn| { setup(&conn).ok(); Ok(conn) })