aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2021-03-23 10:33:30 -0700
committerSean Whitton <spwhitton@spwhitton.name>2021-03-23 12:11:08 -0700
commit2b18eb68088715541e217e112871c14316403981 (patch)
tree6b09de1ef75f7e20c174e1ed333f7e6de4276b43
parentf775cbadd2139d64fc58ca2d4ec2060841d8971a (diff)
downloadconsfigurator-2b18eb68088715541e217e112871c14316403981.tar.gz
add WITH-LOCAL-TEMPORARY-DIRECTORY and export some UIOP dir utils
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
-rw-r--r--src/package.lisp7
-rw-r--r--src/util.lisp9
2 files changed, 15 insertions, 1 deletions
diff --git a/src/package.lisp b/src/package.lisp
index eabc465..45e4a69 100644
--- a/src/package.lisp
+++ b/src/package.lisp
@@ -23,7 +23,9 @@
#:subdirectories
#:directory-files
#:file-exists-p
- #:with-current-directory)
+ #:directory-exists-p
+ #:with-current-directory
+ #:delete-directory-tree)
(:export ;; re-export from UIOP
#:strcat
#:string-prefix-p
@@ -44,7 +46,9 @@
#:subdirectories
#:directory-files
#:file-exists-p
+ #:directory-exists-p
#:with-current-directory
+ #:delete-directory-tree
;; util.lisp
#:lines
@@ -53,6 +57,7 @@
#:symbol-named
#:memstring=
#:plist-to-cmd-args
+ #:with-local-temporary-directory
#:*consfigurator-debug-level*
#:with-indented-inform
diff --git a/src/util.lisp b/src/util.lisp
index f07e90e..2a0d6d5 100644
--- a/src/util.lisp
+++ b/src/util.lisp
@@ -129,6 +129,15 @@ supported."
(doplist (k v plist args)
(push (strcat "--" (string-downcase (symbol-name k)) "=" v) args)))
+(defmacro with-local-temporary-directory ((dir) &body forms)
+ "Execute FORMS with a local temporary directory's pathname in DIR.
+Currently assumes GNU mktemp(1)."
+ `(let ((,dir (ensure-directory-pathname
+ (stripln
+ (run-program "umask 077; mktemp -d" :output :string)))))
+ (unwind-protect (progn ,@forms)
+ (delete-directory-tree ,dir :validate t))))
+
;;;; Progress & debug printing