Skip to content

Commit

Permalink
Fix database path
Browse files Browse the repository at this point in the history
- 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?)
  • Loading branch information
AMDmi3 committed Apr 8, 2016
1 parent 0ef01a5 commit 20b3b52
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions buku
Expand Up @@ -102,14 +102,26 @@ 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.
Returns: connection, cursor
"""

dbpath = os.path.join(os.environ.get('HOME'), '.cache', 'buku')
dbpath = getDataPath()
if not os.path.exists(dbpath):
os.makedirs(dbpath)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 20b3b52

Please sign in to comment.