Be sure db file exist
This commit is contained in:
parent
90f878ca55
commit
5d024b1aa0
1 changed files with 17 additions and 7 deletions
|
@ -1,9 +1,7 @@
|
|||
(in-package :ml-survey/handlers)
|
||||
|
||||
(defvar *survey-data-dir*
|
||||
(ensure-directories-exist (format nil
|
||||
"~adata/survey/"
|
||||
(uiop:getcwd))))
|
||||
(ensure-directories-exist (uiop:merge-pathnames* "data/survey")))
|
||||
|
||||
(defun split-uri (uri)
|
||||
(check-type uri string)
|
||||
|
@ -22,11 +20,23 @@
|
|||
(local-time:now)
|
||||
:format '((:hour 2) ":" (:min 2) ":" (:sec 2))))
|
||||
|
||||
(defun make-db-path (date-str file-str)
|
||||
(pathname (concatenate 'string date-str file-str)))
|
||||
(defun ensure-file-exists (pathname)
|
||||
"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 ()
|
||||
(make-db-path (today) "-surveys-db.lisp"))
|
||||
(defun make-db-file (file-str)
|
||||
"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)
|
||||
(check-type db (or string pathname))
|
||||
|
|
Loading…
Add table
Reference in a new issue