From 916cfc70292efd710240cbe51eaf51a793a2e071 Mon Sep 17 00:00:00 2001 From: ederag Date: Sat, 7 Dec 2019 12:28:23 +0100 Subject: [PATCH] Link from most recent database directory first otherwise it was picking the unused hamster-applet/hamster.db instead of the more recent hamster-time-tracker/hamster.db --- src/hamster/storage/db.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/hamster/storage/db.py b/src/hamster/storage/db.py index 6b646979c..66c0c9654 100644 --- a/src/hamster/storage/db.py +++ b/src/hamster/storage/db.py @@ -115,11 +115,17 @@ def __init_db_file(self, database_dir): # check if we have a database at all if not os.path.exists(db_path): # handle pre-existing hamster-applet database - old_db_path = os.path.join(xdg_data_home, 'hamster-applet', 'hamster.db') - if os.path.exists(old_db_path): - logger.warning("Linking {} with {}".format(old_db_path, db_path)) - os.link(old_db_path, db_path) - else: + # try most recent directories first + # change from hamster-applet to hamster-time-tracker: + # 9f345e5e (2019-09-19) + old_dirs = ['hamster-time-tracker', 'hamster-applet'] + for old_dir in old_dirs: + old_db_path = os.path.join(xdg_data_home, old_dir, 'hamster.db') + if os.path.exists(old_db_path): + logger.warning("Linking {} with {}".format(old_db_path, db_path)) + os.link(old_db_path, db_path) + break + if not os.path.exists(db_path): # make a copy of the empty template hamster.db try: from hamster import defs