guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

03/04: utils: Add 'call-with-temporary-output-file'.


From: guix-commits
Subject: 03/04: utils: Add 'call-with-temporary-output-file'.
Date: Sat, 19 Sep 2020 11:34:32 -0400 (EDT)

civodul pushed a commit to branch core-updates
in repository guix.

commit d845e3af7c410d70d240590d80ed31b8f169c266
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Sat Sep 19 14:11:47 2020 +0200

    utils: Add 'call-with-temporary-output-file'.
    
    * guix/utils.scm: Re-export 'call-with-temporary-output-file'.
    (call-with-temporary-output-file): Move to...
    * guix/build/utils.scm (call-with-temporary-output-file): ... here.
---
 guix/build/utils.scm | 17 +++++++++++++++++
 guix/utils.scm       | 25 ++++++-------------------
 2 files changed, 23 insertions(+), 19 deletions(-)

diff --git a/guix/build/utils.scm b/guix/build/utils.scm
index e872cff..afcb71f 100644
--- a/guix/build/utils.scm
+++ b/guix/build/utils.scm
@@ -53,6 +53,7 @@
             directory-exists?
             executable-file?
             symbolic-link?
+            call-with-temporary-output-file
             call-with-ascii-input-file
             elf-file?
             ar-file?
@@ -198,6 +199,22 @@ introduce the version part."
   "Return #t if FILE is a symbolic link (aka. \"symlink\".)"
   (eq? (stat:type (lstat file)) 'symlink))
 
+(define (call-with-temporary-output-file proc)
+  "Call PROC with a name of a temporary file and open output port to that
+file; close the file and delete it when leaving the dynamic extent of this
+call."
+  (let* ((directory (or (getenv "TMPDIR") "/tmp"))
+         (template  (string-append directory "/guix-file.XXXXXX"))
+         (out       (mkstemp! template)))
+    (dynamic-wind
+      (lambda ()
+        #t)
+      (lambda ()
+        (proc template out))
+      (lambda ()
+        (false-if-exception (close out))
+        (false-if-exception (delete-file template))))))
+
 (define (call-with-ascii-input-file file proc)
   "Open FILE as an ASCII or binary file, and pass the resulting port to
 PROC.  FILE is closed when PROC's dynamic extent is left.  Return the
diff --git a/guix/utils.scm b/guix/utils.scm
index b816c35..7cc3212 100644
--- a/guix/utils.scm
+++ b/guix/utils.scm
@@ -35,7 +35,9 @@
   #:use-module (rnrs io ports)                    ;need 'port-position' etc.
   #:use-module ((rnrs bytevectors) #:select (bytevector-u8-set!))
   #:use-module (guix memoization)
-  #:use-module ((guix build utils) #:select (dump-port mkdir-p 
delete-file-recursively))
+  #:use-module ((guix build utils)
+                #:select (dump-port mkdir-p delete-file-recursively
+                          call-with-temporary-output-file))
   #:use-module ((guix build syscalls) #:select (mkdtemp! fdatasync))
   #:use-module (guix diagnostics)           ;<location>, &error-location, etc.
   #:use-module (ice-9 format)
@@ -59,7 +61,9 @@
 
                &fix-hint
                fix-hint?
-               condition-fix-hint)
+               condition-fix-hint
+
+               call-with-temporary-output-file)
   #:export (strip-keyword-arguments
             default-keyword-arguments
             substitute-keyword-arguments
@@ -94,7 +98,6 @@
             tarball-sans-extension
             compressed-file?
             switch-symlinks
-            call-with-temporary-output-file
             call-with-temporary-directory
             with-atomic-file-output
 
@@ -677,22 +680,6 @@ REPLACEMENT."
                        (substring str start index)
                        pieces))))))))
 
-(define (call-with-temporary-output-file proc)
-  "Call PROC with a name of a temporary file and open output port to that
-file; close the file and delete it when leaving the dynamic extent of this
-call."
-  (let* ((directory (or (getenv "TMPDIR") "/tmp"))
-         (template  (string-append directory "/guix-file.XXXXXX"))
-         (out       (mkstemp! template)))
-    (dynamic-wind
-      (lambda ()
-        #t)
-      (lambda ()
-        (proc template out))
-      (lambda ()
-        (false-if-exception (close out))
-        (false-if-exception (delete-file template))))))
-
 (define (call-with-temporary-directory proc)
   "Call PROC with a name of a temporary directory; close the directory and
 delete it when leaving the dynamic extent of this call."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]