From 8304e6b74bd8a8ebac03ef0db9c78b49779ef08f Mon Sep 17 00:00:00 2001 From: Javier Olaechea Date: Sun, 17 Aug 2014 16:46:57 -0500 Subject: [PATCH] More robust directory changing - Doesn't fail when the directory is missing a trailing '/' - When directory doesn't exist it signals an informative condition. --- src/packages.lisp | 4 +++- src/util.lisp | 10 +++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/packages.lisp b/src/packages.lisp index dd6dccd..a9a3786 100644 --- a/src/packages.lisp +++ b/src/packages.lisp @@ -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* diff --git a/src/util.lisp b/src/util.lisp index b9c76a0..1811bde 100644 --- a/src/util.lisp +++ b/src/util.lisp @@ -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)