diff options
author | Tom Willemsen | 2013-03-23 13:24:43 +0100 |
---|---|---|
committer | Tom Willemsen | 2013-03-23 13:24:43 +0100 |
commit | dd47751a43773cc9a1732e3665940da539bdc150 (patch) | |
tree | 60466103ed86a436fc312f2dfa4fcb4db2b5efc6 /lisp | |
parent | 9e747fde54181853a534df51e07cac4e730e317e (diff) | |
download | clark-dd47751a43773cc9a1732e3665940da539bdc150.tar.gz clark-dd47751a43773cc9a1732e3665940da539bdc150.zip |
Place the database in XDG_DATA_HOME if possible
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/clark.lisp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/lisp/clark.lisp b/lisp/clark.lisp index 2907931..256bcdd 100644 --- a/lisp/clark.lisp +++ b/lisp/clark.lisp @@ -55,7 +55,7 @@ (sqlite-error () (get-tag-id tag))))) (insert-bookmark-tag bookmark-id tag-id))) tags))) -(defun check-db (name) +(defun ensure-db-exists (name) "Connect to the database, possibly creating it." (let ((db-exists (probe-file name))) (setf *db* (connect name)) @@ -76,6 +76,14 @@ The result contains the url and the name of the bookmark." (statement-column-value statement 1)) finally (finalize-statement statement)))) +(defun get-db-location () + "Get the location of the database." + (pathname + (apply 'concatenate 'string + (or (sb-ext:posix-getenv "XDG_DATA_HOME") + (list (sb-ext:posix-getenv "HOME") "/.local/share")) + '("/clark/bookmarks.db")))) + (defun get-tag-id (name) "Get the rowid of tag NAME." (execute-single *db* "SELECT rowid FROM tag WHERE name = ?" name)) @@ -95,6 +103,12 @@ The result contains the url and the name of the bookmark." (execute-non-query *db* "INSERT INTO tag VALUES (?)" name) (last-insert-rowid *db*)) +(defun load-db () + "Load the database." + (let ((db-location (get-db-location))) + (ensure-directories-exist db-location) + (ensure-db-exists db-location))) + (eval-when (:compile-toplevel :load-toplevel) (defun make-command-name (base) "Turn BASE into the name of a possible command." @@ -169,7 +183,7 @@ BM should be a list containing the url and name of the bookmark." Connect to the database, parse command-line arguments, execute and then disconnect." - (check-db "test2.db") + (load-db) (if (> (length args) 1) (parse-args (cdr args)) (map nil #'print-bookmark (get-bookmarks))) |