Skip to content

Commit

Permalink
Merge pull request #488 from ederag/fix-database-links
Browse files Browse the repository at this point in the history
Link from most recent database directory first
  • Loading branch information
ederag authored Jan 28, 2020
2 parents fd699c4 + 916cfc7 commit 339a8e1
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 @@ -119,11 +119,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 339a8e1

Please sign in to comment.