More robust directory changing

- Doesn't fail when the directory is missing a trailing '/'
     - When directory doesn't exist it signals an informative
       condition.
This commit is contained in:
Javier Olaechea 2014-08-17 16:46:57 -05:00
parent 221a9cbe86
commit 8304e6b74b
2 changed files with 12 additions and 2 deletions

View file

@ -8,7 +8,9 @@
(:import-from :closure-template #:compile-template) (:import-from :closure-template #:compile-template)
(:import-from :local-time #:format-rfc1123-timestring) (:import-from :local-time #:format-rfc1123-timestring)
(:import-from :uiop #:getcwd (:import-from :uiop #:getcwd
#:chdir) #:chdir
#:ensure-directory-pathname
#:directory-exists-p)
(:export #:main (:export #:main
#:preview #:preview
#:*config* #:*config*

View file

@ -30,9 +30,17 @@ BODY on files that match the given extension."
#',extension-p #',extension-p
(constantly t)))))) (constantly t))))))
(define-condition directory-does-not-exist (error)
((directory :initarg dir :reader dir))
(:report (lambda (c stream)
(format stream "The directory '~A' does not exist" (dir c)))))
(defun (setf getcwd) (path) (defun (setf getcwd) (path)
"Change the operating system's current directory to PATH." "Change the operating system's current directory to PATH."
(chdir path) (setf path (ensure-directory-pathname path))
(or (and (directory-exists-p path)
(chdir path))
(error 'directory-does-not-exist :dir path))
path) path)
(defmacro with-current-directory (path &body body) (defmacro with-current-directory (path &body body)