guix-commits
[Top][All Lists]
Advanced

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

02/03: import: Gracefully report import failures.


From: Ludovic Courtès
Subject: 02/03: import: Gracefully report import failures.
Date: Tue, 17 May 2016 12:03:35 +0000 (UTC)

civodul pushed a commit to branch master
in repository guix.

commit 149590380adb240e0993931b4f72e6f285b24483
Author: Ludovic Courtès <address@hidden>
Date:   Tue May 17 13:41:07 2016 +0200

    import: Gracefully report import failures.
    
    Previously, something like 'guix import gnu which' would spit out a
    backtrace if, say, the 'which' tarball could not be authenticated.
    
    * guix/upstream.scm (download-tarball): Mention failure modes in
    docstring.
    * guix/import/gnu.scm (gnu-package->sexp): Return #f when
    'download-tarball' returns #f.
    * guix/scripts/import.scm (guix-import): Call 'leave' when IMPORTER does
    not return a (package ...) sexp.
---
 guix/import/gnu.scm     |   48 +++++++++++++++++++++++++----------------------
 guix/scripts/import.scm |    8 ++++++--
 guix/upstream.scm       |    5 +++--
 3 files changed, 35 insertions(+), 26 deletions(-)

diff --git a/guix/import/gnu.scm b/guix/import/gnu.scm
index 834f0ae..2cfb46b 100644
--- a/guix/import/gnu.scm
+++ b/guix/import/gnu.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2014, 2015 Ludovic Courtès <address@hidden>
+;;; Copyright © 2014, 2015, 2016 Ludovic Courtès <address@hidden>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -55,8 +55,8 @@
 (define* (gnu-package->sexp package release
                             #:key (key-download 'interactive))
   "Return the 'package' sexp for the RELEASE (a <gnu-release>) of PACKAGE (a
-<gnu-package>).  Use KEY-DOWNLOAD as the OpenPGP key download policy (see
-'download-tarball' for details.)"
+<gnu-package>), or #f upon failure.  Use KEY-DOWNLOAD as the OpenPGP key
+download policy (see 'download-tarball' for details.)"
   (define name
     (gnu-package-name package))
 
@@ -79,25 +79,29 @@
     (find (cute string-suffix? (string-append archive-type ".sig") <>)
           (upstream-source-signature-urls release)))
 
-  (let ((tarball (with-store store
-                   (download-tarball store url sig-url
-                                     #:key-download key-download))))
-    `(package
-       (name ,name)
-       (version ,(upstream-source-version release))
-       (source (origin
-                 (method url-fetch)
-                 (uri (string-append ,url-base version
-                                     ,(string-append ".tar." archive-type)))
-                 (sha256
-                  (base32
-                   ,(bytevector->nix-base32-string (file-sha256 tarball))))))
-       (build-system gnu-build-system)
-       (synopsis ,(gnu-package-doc-summary package))
-       (description ,(gnu-package-doc-description package))
-       (home-page ,(match (gnu-package-doc-urls package)
-                     ((head . tail) (qualified-url head))))
-       (license find-by-yourself!))))
+  (with-store store
+    (match (download-tarball store url sig-url
+                             #:key-download key-download)
+      ((? string? tarball)
+       `(package
+          (name ,name)
+          (version ,(upstream-source-version release))
+          (source (origin
+                    (method url-fetch)
+                    (uri (string-append ,url-base version
+                                        ,(string-append ".tar." archive-type)))
+                    (sha256
+                     (base32
+                      ,(bytevector->nix-base32-string
+                        (file-sha256 tarball))))))
+          (build-system gnu-build-system)
+          (synopsis ,(gnu-package-doc-summary package))
+          (description ,(gnu-package-doc-description package))
+          (home-page ,(match (gnu-package-doc-urls package)
+                        ((head . tail) (qualified-url head))))
+          (license find-by-yourself!)))
+      (#f                     ;failure to download or authenticate the tarball
+       #f))))
 
 (define* (gnu->guix-package name
                             #:key (key-download 'interactive))
diff --git a/guix/scripts/import.scm b/guix/scripts/import.scm
index cf8fc07..e54744f 100644
--- a/guix/scripts/import.scm
+++ b/guix/scripts/import.scm
@@ -107,6 +107,10 @@ Run IMPORTER with ARGS.\n"))
      (show-version-and-exit "guix import"))
     ((importer args ...)
      (if (member importer importers)
-         (let ((expr (apply (resolve-importer importer) args)))
-           (pretty-print expr (newline-rewriting-port (current-output-port))))
+         (match (apply (resolve-importer importer) args)
+           ((and expr ('package _ ...))
+            (pretty-print expr (newline-rewriting-port
+                                (current-output-port))))
+           (x
+            (leave (_ "'~a' import failed~%") importer)))
          (leave (_ "~a: invalid importer~%") importer)))))
diff --git a/guix/upstream.scm b/guix/upstream.scm
index 167c9ff..1815737 100644
--- a/guix/upstream.scm
+++ b/guix/upstream.scm
@@ -143,8 +143,9 @@ no update is needed or known."
                            #:key (key-download 'interactive))
   "Download the tarball at URL to the store; check its OpenPGP signature at
 SIGNATURE-URL, unless SIGNATURE-URL is false.  On success, return the tarball
-file name.  KEY-DOWNLOAD specifies a download policy for missing OpenPGP keys;
-allowed values: 'interactive' (default), 'always', and 'never'."
+file name; return #f on failure (network failure or authentication failure).
+KEY-DOWNLOAD specifies a download policy for missing OpenPGP keys; allowed
+values: 'interactive' (default), 'always', and 'never'."
   (let ((tarball (download-to-store store url)))
     (if (not signature-url)
         tarball



reply via email to

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