From dd47751a43773cc9a1732e3665940da539bdc150 Mon Sep 17 00:00:00 2001 From: Tom Willemsen Date: Sat, 23 Mar 2013 13:24:43 +0100 Subject: Place the database in XDG_DATA_HOME if possible --- lisp/clark.lisp | 18 ++++++++++++++++-- 1 file 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))) -- cgit v1.2.3-54-g00ecf