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:
parent
221a9cbe86
commit
8304e6b74b
2 changed files with 12 additions and 2 deletions
|
@ -8,7 +8,9 @@
|
|||
(:import-from :closure-template #:compile-template)
|
||||
(:import-from :local-time #:format-rfc1123-timestring)
|
||||
(:import-from :uiop #:getcwd
|
||||
#:chdir)
|
||||
#:chdir
|
||||
#:ensure-directory-pathname
|
||||
#:directory-exists-p)
|
||||
(:export #:main
|
||||
#:preview
|
||||
#:*config*
|
||||
|
|
|
@ -30,9 +30,17 @@ BODY on files that match the given extension."
|
|||
#',extension-p
|
||||
(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)
|
||||
"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)
|
||||
|
||||
(defmacro with-current-directory (path &body body)
|
||||
|
|
Loading…
Add table
Reference in a new issue