From d54ae15d41569b92f2d7c7e2270dda7c1c0718a0 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Sun, 29 Mar 2020 13:29:05 -0700 Subject: [PATCH] fixup! Rework database fallback --- src/util.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/util.rs b/src/util.rs index 3df7eac..80dcccd 100644 --- a/src/util.rs +++ b/src/util.rs @@ -22,19 +22,21 @@ pub fn path_to_bytes>(path: &P) -> Option<&[u8]> { } pub fn get_db() -> Result { - let mut db_file = config::zo_data_dir()?; - db_file.push("db.zo"); + let mut db_path = config::zo_data_dir()?; + db_path.push("db.zo"); // FIXME: fallback to old database location; remove in next breaking version - if let Some(mut old_db) = dirs::home_dir() { - old_db.push(".zo"); + if !db_path.is_file() { + if let Some(mut old_db_path) = dirs::home_dir() { + old_db_path.push(".zo"); - if old_db.is_file() && !db_file.is_file() { - return DB::open_and_migrate(old_db, db_file); + if old_db_path.is_file() { + return DB::open_and_migrate(old_db_path, db_path); + } } } - DB::open(db_file) + DB::open(db_path) } pub fn get_current_time() -> Result {