-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtmpdir.lisp
More file actions
23 lines (21 loc) · 982 Bytes
/
tmpdir.lisp
File metadata and controls
23 lines (21 loc) · 982 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
(in-package :tmpdir)
(defun mkdtemp (&key (parent (uiop:temporary-directory)) prefix suffix )
;; this isn't the most efficient way to do it, but it get's the job
;; done for V1.
(uiop:with-temporary-file (:stream unused :pathname name :prefix prefix :suffix suffix :type "tmp")
(uiop:delete-file-if-exists name)
(let ((name (pathname (format nil "~a/"(namestring name)))))
(ensure-directories-exist name)
name)))
(defmacro with-tmpdir ((name &rest args) &body body*)
(let ((tmp-name (gensym)))
`(let ((,tmp-name (mkdtemp ,@args)))
(let ((,name ,tmp-name)) ;; this let's us do things like (with-tmpdir(*foobar*) ..)
(unwind-protect
(progn
,@body*)
;; workaround bug in cl-fad for lispworks, see
;; https://github.com/edicl/cl-fad/pull/30
(let (#+lispworks
(system:*directory-link-transparency* nil))
(fad:delete-directory-and-files ,tmp-name)))))))