From 861693f3e71fed8663a3ef9c336c3f3345e1e039 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Sun, 21 Apr 2013 22:40:23 +0200 Subject: Factorize `download-and-store'. * guix/download.scm (download-to-store): New procedure. * guix/scripts/download.scm (fetch-and-store): Remove. (guix-download): Use `download-to-store' instead. * guix/ui.scm (call-with-temporary-output-file): Move to... * guix/utils.scm (call-with-temporary-output-file): ... here. --- guix/utils.scm | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'guix/utils.scm') diff --git a/guix/utils.scm b/guix/utils.scm index f13e585e2b..ad1c463be8 100644 --- a/guix/utils.scm +++ b/guix/utils.scm @@ -60,6 +60,7 @@ version-compare version>? package-name->name+version + call-with-temporary-output-file fold2)) @@ -464,6 +465,21 @@ introduce the version part." ((head tail ...) (loop tail (cons head prefix)))))) +(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* ((template (string-copy "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 fold2 (case-lambda ((proc seed1 seed2 lst) -- cgit v1.2.3