Skip to content

Commit

Permalink
Link from most recent database directory first
Browse files Browse the repository at this point in the history
otherwise it was picking the unused hamster-applet/hamster.db
instead of the more recent hamster-time-tracker/hamster.db
  • Loading branch information
ederag committed Dec 7, 2019
1 parent a626f40 commit 916cfc7
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/hamster/storage/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 916cfc7

Please sign in to comment.