diff options
author | Arun Isaac | 2022-07-04 18:21:36 +0530 |
---|---|---|
committer | Arun Isaac | 2022-07-04 18:25:42 +0530 |
commit | 9e364c12ca7f27b028e4e82ceb719d05893e2c33 (patch) | |
tree | 311607e7c32e7b968352104b24952ec301603511 | |
parent | c1af832f5aac81873e862a2b7908b4bdb29677ed (diff) | |
download | tissue-9e364c12ca7f27b028e4e82ceb719d05893e2c33.tar.gz tissue-9e364c12ca7f27b028e4e82ceb719d05893e2c33.tar.lz tissue-9e364c12ca7f27b028e4e82ceb719d05893e2c33.zip |
utils: Add call-with-temporary-directory utility.
* tissue/utils.scm: Import (ice-9 filesystem).
(call-with-temporary-directory): New function.
-rw-r--r-- | tissue/utils.scm | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tissue/utils.scm b/tissue/utils.scm index 2eccc4f..7fac814 100644 --- a/tissue/utils.scm +++ b/tissue/utils.scm @@ -20,10 +20,12 @@ #:use-module (rnrs io ports) #:use-module (srfi srfi-19) #:use-module (srfi srfi-26) + #:use-module (ice-9 filesystem) #:use-module (ice-9 popen) #:export (string-remove-prefix human-date-string call-with-current-directory + call-with-temporary-directory call-with-output-pipe get-line-dos-or-unix memoize-thunk)) @@ -60,6 +62,16 @@ directory after THUNK returns." thunk (cut chdir original-current-directory)))) +(define (call-with-temporary-directory proc) + "Call PROC with a new temporary directory, and delete it when PROC +returns or exits non-locally." + (let ((temporary-directory (mkdtemp "XXXXXX"))) + (dynamic-wind (const #t) + (cut proc temporary-directory) + (lambda () + (when (file-exists? temporary-directory) + (delete-file-recursively temporary-directory)))))) + (define (call-with-output-pipe proc program . args) "Execute PROGRAM ARGS ... in a subprocess with a pipe to it. Call PROC with an output port to that pipe. Close the pipe once PROC exits, even |