Set data dir in users home dir
This commit is contained in:
parent
549bf83d28
commit
2337187206
2 changed files with 25 additions and 6 deletions
|
@ -1,9 +1,20 @@
|
||||||
(in-package :ml-survey/handlers)
|
(in-package :ml-survey/handlers)
|
||||||
|
|
||||||
(defun surveys-data-dir ()
|
(defun base-dir ()
|
||||||
(let ((data-dir (uiop:merge-pathnames* "data/surveys/")))
|
(if (uiop:os-unix-p)
|
||||||
(ensure-directories-exist data-dir)
|
(format nil "~a/" (uiop:getenv "XDG_DATA_HOME"))
|
||||||
data-dir))
|
(format nil "~a/" (uiop:getenv "LOCALAPPDATA"))))
|
||||||
|
|
||||||
|
(defun app-dir ()
|
||||||
|
(uiop:merge-pathnames* "ml-survey/" (base-dir)))
|
||||||
|
|
||||||
|
(defun data-dir ()
|
||||||
|
(uiop:merge-pathnames* "data/surveys/" (app-dir)))
|
||||||
|
|
||||||
|
(defun ensure-data-dir ()
|
||||||
|
(let ((data-dir (data-dir)))
|
||||||
|
(ensure-directories-exist (data-dir))
|
||||||
|
data-dir))
|
||||||
|
|
||||||
(defun split-uri (uri)
|
(defun split-uri (uri)
|
||||||
(check-type uri string)
|
(check-type uri string)
|
||||||
|
@ -39,10 +50,18 @@
|
||||||
(format stream "")))
|
(format stream "")))
|
||||||
pathname)
|
pathname)
|
||||||
|
|
||||||
|
(defun ensure-data-file-exist (survey-id questionnaire-id)
|
||||||
|
(let ((path (format nil "~a~a/~a.lisp"
|
||||||
|
(ensure-data-dir)
|
||||||
|
survey-id
|
||||||
|
questionnaire-id)))
|
||||||
|
(ensure-directories-exist path)
|
||||||
|
(ensure-file-exist path)))
|
||||||
|
|
||||||
(defun make-db-file (file)
|
(defun make-db-file (file)
|
||||||
"Prepare and ensure a database file at FILE-STR path."
|
"Prepare and ensure a database file at FILE-STR path."
|
||||||
(check-type file string)
|
(check-type file string)
|
||||||
(let ((path (uiop:merge-pathnames* file)))
|
(let ((path (uiop:merge-pathnames* file (ensure-data-dir))))
|
||||||
(ensure-file-exist path)))
|
(ensure-file-exist path)))
|
||||||
|
|
||||||
(defun make-surveys-db-file ()
|
(defun make-surveys-db-file ()
|
||||||
|
|
|
@ -38,7 +38,7 @@ Returns a list of integers."
|
||||||
(with-slots (id data-dir properties) survey
|
(with-slots (id data-dir properties) survey
|
||||||
(setf data-dir (uiop:merge-pathnames*
|
(setf data-dir (uiop:merge-pathnames*
|
||||||
(format nil "~a/" id)
|
(format nil "~a/" id)
|
||||||
(surveys-data-dir)))
|
(ensure-data-dir)))
|
||||||
(setf properties (first (rest (assoc (parse-integer id)
|
(setf properties (first (rest (assoc (parse-integer id)
|
||||||
(load-response (make-surveys-db-file))))))))
|
(load-response (make-surveys-db-file))))))))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue