diff options
author | Ludovic Courtès <ludo@gnu.org> | 2014-01-08 22:06:54 +0100 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2014-01-08 22:06:54 +0100 |
commit | 2f265602ff23e41f75932aa568fe62e149e3cb9d (patch) | |
tree | 3ff7d0b4be81246a4dfd3df414e163d8cbdc4990 /guix/utils.scm | |
parent | aa6b0d6bf01aba60c6b5524e4422e7a4cebf01e4 (diff) | |
parent | 1d6816f98ca1746f0b627a6dee9c0adbbf7533c4 (diff) | |
download | gnu-guix-2f265602ff23e41f75932aa568fe62e149e3cb9d.tar gnu-guix-2f265602ff23e41f75932aa568fe62e149e3cb9d.tar.gz |
Merge branch 'master' into core-updates
Diffstat (limited to 'guix/utils.scm')
-rw-r--r-- | guix/utils.scm | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/guix/utils.scm b/guix/utils.scm index b730340eda..04a74ee29a 100644 --- a/guix/utils.scm +++ b/guix/utils.scm @@ -67,6 +67,7 @@ file-extension file-sans-extension call-with-temporary-output-file + with-atomic-file-output fold2 filtered-port)) @@ -426,6 +427,21 @@ call." (false-if-exception (close out)) (false-if-exception (delete-file template)))))) +(define (with-atomic-file-output file proc) + "Call PROC with an output port for the file that is going to replace FILE. +Upon success, FILE is atomically replaced by what has been written to the +output port, and PROC's result is returned." + (let* ((template (string-append file ".XXXXXX")) + (out (mkstemp! template))) + (with-throw-handler #t + (lambda () + (let ((result (proc out))) + (close out) + (rename-file template file) + result)) + (lambda (key . args) + (false-if-exception (delete-file template)))))) + (define fold2 (case-lambda ((proc seed1 seed2 lst) |