Skip to content

Commit 20b3b52

Browse files
committed
Fix database path
- Don't use ~/.cache, it's intended to store non-essential data files and may be purged at any time - Instead, follow XDG and use $XDG_DATA_HOME or ~/.local/share/buku - Fallback to current directory if HOME is not defined (Windows?)
1 parent 0ef01a5 commit 20b3b52

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

buku

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,26 @@ class BMHTMLParser(HTMLParser.HTMLParser):
102102

103103

104104

105+
def getDataPath():
106+
data_home = os.environ.get('XDG_DATA_HOME')
107+
if data_home is None:
108+
if os.environ.get('HOME') is None:
109+
data_home = '.'
110+
else:
111+
data_home = os.path.join(os.environ.get('HOME'), '.local', 'share')
112+
113+
return os.path.join(data_home, 'buku')
114+
115+
116+
105117
def initdb():
106118
"""Initialize the database connection. Create DB file and/or bookmarks table
107119
if they don't exist. Alert on encryption options on first execution.
108120
109121
Returns: connection, cursor
110122
"""
111123

112-
dbpath = os.path.join(os.environ.get('HOME'), '.cache', 'buku')
124+
dbpath = getDataPath()
113125
if not os.path.exists(dbpath):
114126
os.makedirs(dbpath)
115127

@@ -663,7 +675,7 @@ def get_filehash(filepath):
663675
def encrypt_file():
664676
"""Encrypt the bookmarks database file"""
665677

666-
dbpath = os.path.join(os.environ.get('HOME'), '.cache', 'buku', 'bookmarks.db')
678+
dbpath = os.path.join(getDataPath(), 'bookmarks.db')
667679
encpath = dbpath + '.enc'
668680
if not os.path.exists(dbpath):
669681
print("%s missing. Already encrypted?" % dbpath)
@@ -724,7 +736,7 @@ def encrypt_file():
724736
def decrypt_file():
725737
"""Decrypt the bookmarks database file"""
726738

727-
dbpath = os.path.join(os.environ.get('HOME'), '.cache', 'buku', 'bookmarks.db')
739+
dbpath = os.path.join(getDataPath(), 'bookmarks.db')
728740
encpath = dbpath + '.enc'
729741
if not os.path.exists(encpath):
730742
printmsg((encpath + " missing"), "ERROR")

0 commit comments

Comments
 (0)