guix-commits
[Top][All Lists]
Advanced

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

01/02: build: hg: Handle fetch errors.


From: guix-commits
Subject: 01/02: build: hg: Handle fetch errors.
Date: Tue, 6 Oct 2020 04:25:09 -0400 (EDT)

mothacehe pushed a commit to branch master
in repository guix.

commit a5a3f813c74aa8143af1e42a3d754f1bf7be2fb0
Author: zimoun <zimon.toutoune@gmail.com>
AuthorDate: Mon Oct 5 18:36:34 2020 +0200

    build: hg: Handle fetch errors.
    
    * guix/build/hg.scm (hg-fetch): Add 'guard' to handle errors.
    
    Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>
---
 guix/build/hg.scm | 50 +++++++++++++++++++++++++++++++++-----------------
 1 file changed, 33 insertions(+), 17 deletions(-)

diff --git a/guix/build/hg.scm b/guix/build/hg.scm
index b3e3ff7..1cceb63 100644
--- a/guix/build/hg.scm
+++ b/guix/build/hg.scm
@@ -2,6 +2,7 @@
 ;;; Copyright © 2016 Ricardo Wurmus <rekado@elephly.net>
 ;;; Copyright © 2018 Mark H Weaver <mhw@netris.org>
 ;;; Copyright © 2018 Björn Höfling <bjoern.hoefling@bjoernhoefling.de>
+;;; Copyright © 2020 Simon Tournier <zimon.toutoune@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -20,6 +21,8 @@
 
 (define-module (guix build hg)
   #:use-module (guix build utils)
+  #:use-module (srfi srfi-34)
+  #:use-module (ice-9 format)
   #:export (hg-fetch))
 
 ;;; Commentary:
@@ -35,22 +38,35 @@
   "Fetch CHANGESET from URL into DIRECTORY.  CHANGESET must be a valid
 Mercurial changeset identifier.  Return #t on success, #f otherwise."
 
-  (invoke hg-command
-          "clone" url
-          "--rev" changeset
-          ;; Disable TLS certificate verification.  The hash of
-          ;; the checkout is known in advance anyway.
-          "--insecure"
-          directory)
-
-  ;; The contents of '.hg' vary as a function of the current
-  ;; status of the Mercurial repo.  Since we want a fixed
-  ;; output, this directory needs to be taken out.
-  ;; Since the '.hg' file is also in sub-modules, we have to
-  ;; search for it in all sub-directories.
-  (for-each delete-file-recursively
-            (find-files directory "^\\.hg$" #:directories? #t))
-
-  #t)
+  (mkdir-p directory)
+
+  (guard (c ((invoke-error? c)
+             (format (current-error-port)
+                     "hg-fetch: '~a~{ ~a~}' failed with exit code ~a~%"
+                     (invoke-error-program c)
+                     (invoke-error-arguments c)
+                     (or (invoke-error-exit-status c)
+                         (invoke-error-stop-signal c)
+                         (invoke-error-term-signal c)))
+             (delete-file-recursively directory)
+             #f))
+    (with-directory-excursion directory
+      (invoke hg-command
+              "clone" url
+              "--rev" changeset
+              ;; Disable TLS certificate verification.  The hash of
+              ;; the checkout is known in advance anyway.
+              "--insecure"
+              directory)
+
+      ;; The contents of '.hg' vary as a function of the current
+      ;; status of the Mercurial repo.  Since we want a fixed
+      ;; output, this directory needs to be taken out.
+      ;; Since the '.hg' file is also in sub-modules, we have to
+      ;; search for it in all sub-directories.
+      (for-each delete-file-recursively
+                (find-files directory "^\\.hg$" #:directories? #t))
+
+      #t)))
 
 ;;; hg.scm ends here



reply via email to

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