... |
... |
@@ -22,7 +22,8 @@ |
22
|
22
|
read-char-no-edit listen-skip-whitespace concat-pnames
|
23
|
23
|
iterate once-only collect do-anonymous undefined-value
|
24
|
24
|
required-argument define-hash-cache defun-cached
|
25
|
|
- cache-hash-eq do-hash))
|
|
25
|
+ cache-hash-eq do-hash
|
|
26
|
+ with-temporary-file))
|
26
|
27
|
|
27
|
28
|
(import 'lisp::whitespace-char-p)
|
28
|
29
|
|
... |
... |
@@ -622,7 +623,7 @@ |
622
|
623
|
decoding-error
|
623
|
624
|
encoding-error)
|
624
|
625
|
&parse-body (forms decls))
|
625
|
|
- "A temporary file is opened using the Open-args and bound to the
|
|
626
|
+ _N"A temporary file is opened using the Open-args and bound to the
|
626
|
627
|
variable Var. The name of the temporary file uses Template-prefix
|
627
|
628
|
for the name. If the temporary file cannot be opened, the forms are
|
628
|
629
|
not evaluated. The Forms are executed, and when they terminate,
|
... |
... |
@@ -639,19 +640,19 @@ |
639
|
640
|
(template (gensym "TEMPLATE-")))
|
640
|
641
|
|
641
|
642
|
`(let* ((,template (concatenate 'string
|
642
|
|
- ,template-prefix
|
643
|
|
- "XXXXXX"))
|
644
|
|
- (,var (lisp::make-fd-stream (unix::unix-mkstemp ,template)
|
645
|
|
- :auto-close t
|
646
|
|
- :file ,template
|
647
|
|
- :output t
|
648
|
|
- :input t
|
649
|
|
- :element-type ',element-type
|
650
|
|
- :external-format ,external-format
|
651
|
|
- :decoding-error ,decoding-error
|
652
|
|
- :encoding-error ,encoding-error
|
653
|
|
- :buffering ,buffering))
|
654
|
|
- (,abortp t))
|
|
643
|
+ ,template-prefix
|
|
644
|
+ "XXXXXX"))
|
|
645
|
+ (,var (lisp::make-fd-stream (unix::unix-mkstemp ,template)
|
|
646
|
+ :auto-close t
|
|
647
|
+ :file ,template
|
|
648
|
+ :output t
|
|
649
|
+ :input t
|
|
650
|
+ :element-type ',element-type
|
|
651
|
+ :external-format ,external-format
|
|
652
|
+ :decoding-error ,decoding-error
|
|
653
|
+ :encoding-error ,encoding-error
|
|
654
|
+ :buffering ,buffering))
|
|
655
|
+ (,abortp t))
|
655
|
656
|
,@decls
|
656
|
657
|
(unwind-protect
|
657
|
658
|
(multiple-value-prog1
|
... |
... |
@@ -659,3 +660,21 @@ |
659
|
660
|
(setq ,abortp nil))
|
660
|
661
|
(when ,var
|
661
|
662
|
(close ,var :abort ,abortp))))))
|
|
663
|
+
|
|
664
|
+;; WITH-TEMPORARY-DIRECTORY -- Public
|
|
665
|
+(defmacro with-temporary-directory ((var template-prefix)
|
|
666
|
+ &parse-body (forms decls))
|
|
667
|
+ _N"Create a temporary directory using Template-prefix as the name of the directory."
|
|
668
|
+ (let ((template (gensym "TEMPLATE-")))
|
|
669
|
+ `(let ((,template (concatenate 'string ,template-prefix
|
|
670
|
+ "XXXXXX")))
|
|
671
|
+ ,@decls
|
|
672
|
+ (let ((,var (unix::unix-mkdtemp ,template)))
|
|
673
|
+ (unless ,var
|
|
674
|
+ (error "Could not create temporary directory using template ~A"
|
|
675
|
+ ,template))
|
|
676
|
+ (unwind-protect
|
|
677
|
+ (multiple-value-prog1
|
|
678
|
+ (progn ,@forms)))
|
|
679
|
+ ;; Remove the directory
|
|
680
|
+ (unix:unix-rmdir ,var))))) |