Be sure db file exist

This commit is contained in:
Marcus Kammer 2024-06-05 16:48:40 +02:00
parent 90f878ca55
commit 5d024b1aa0

View file

@ -1,9 +1,7 @@
(in-package :ml-survey/handlers) (in-package :ml-survey/handlers)
(defvar *survey-data-dir* (defvar *survey-data-dir*
(ensure-directories-exist (format nil (ensure-directories-exist (uiop:merge-pathnames* "data/survey")))
"~adata/survey/"
(uiop:getcwd))))
(defun split-uri (uri) (defun split-uri (uri)
(check-type uri string) (check-type uri string)
@ -22,11 +20,23 @@
(local-time:now) (local-time:now)
:format '((:hour 2) ":" (:min 2) ":" (:sec 2)))) :format '((:hour 2) ":" (:min 2) ":" (:sec 2))))
(defun make-db-path (date-str file-str) (defun ensure-file-exists (pathname)
(pathname (concatenate 'string date-str file-str))) "Ensure that a file specified by PATHNAME exists, create it if it doesn't."
(unless (uiop:file-exists-p pathname)
(with-open-file (stream pathname
:direction :output
:if-exists :overwrite
:if-does-not-exist :create)
(format stream "")))
pathname)
(defun make-surveys-db-path () (defun make-db-file (file-str)
(make-db-path (today) "-surveys-db.lisp")) "Prepare and ensure a database file at FILE-STR path."
(let ((path (uiop:merge-pathnames* file-str)))
(ensure-file-exits (truename path))))
(defun make-surveys-db-file ()
(make-db-file "surveys-db.lisp"))
(defun load-response (db) (defun load-response (db)
(check-type db (or string pathname)) (check-type db (or string pathname))