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?)
This commit is contained in:
Dmitry Marakasov 2016-04-08 00:34:05 +03:00
parent 0ef01a5419
commit 20b3b52629

18
buku
View File

@ -102,6 +102,18 @@ class BMHTMLParser(HTMLParser.HTMLParser):
def getDataPath():
data_home = os.environ.get('XDG_DATA_HOME')
if data_home is None:
if os.environ.get('HOME') is None:
data_home = '.'
else:
data_home = os.path.join(os.environ.get('HOME'), '.local', 'share')
return os.path.join(data_home, 'buku')
def initdb():
"""Initialize the database connection. Create DB file and/or bookmarks table
if they don't exist. Alert on encryption options on first execution.
@ -109,7 +121,7 @@ def initdb():
Returns: connection, cursor
"""
dbpath = os.path.join(os.environ.get('HOME'), '.cache', 'buku')
dbpath = getDataPath()
if not os.path.exists(dbpath):
os.makedirs(dbpath)
@ -663,7 +675,7 @@ def get_filehash(filepath):
def encrypt_file():
"""Encrypt the bookmarks database file"""
dbpath = os.path.join(os.environ.get('HOME'), '.cache', 'buku', 'bookmarks.db')
dbpath = os.path.join(getDataPath(), 'bookmarks.db')
encpath = dbpath + '.enc'
if not os.path.exists(dbpath):
print("%s missing. Already encrypted?" % dbpath)
@ -724,7 +736,7 @@ def encrypt_file():
def decrypt_file():
"""Decrypt the bookmarks database file"""
dbpath = os.path.join(os.environ.get('HOME'), '.cache', 'buku', 'bookmarks.db')
dbpath = os.path.join(getDataPath(), 'bookmarks.db')
encpath = dbpath + '.enc'
if not os.path.exists(encpath):
printmsg((encpath + " missing"), "ERROR")