GNU bug report logs - #55941
[PATCH core-updates 0/3] Move switch-symlinks to (guix build utils)

Previous Next

Package: guix-patches;

Reported by: Arun Isaac <arunisaac <at> systemreboot.net>

Date: Mon, 13 Jun 2022 12:14:02 UTC

Severity: normal

Tags: patch

Done: Arun Isaac <arunisaac <at> systemreboot.net>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Arun Isaac <arunisaac <at> systemreboot.net>
To: 55941 <at> debbugs.gnu.org, Maxime Devos <maximedevos <at> telenet.be>
Cc: Arun Isaac <arunisaac <at> systemreboot.net>
Subject: [bug#55941] [PATCH core-updates 2/3] utils: Make switch-symlinks robust against interruption.
Date: Mon, 13 Jun 2022 17:45:22 +0530
* guix/build/utils.scm (switch-symlinks): Delete pivot link if it already
exists.

Co-authored-by: Maxime Devos <maximedevos <at> telenet.be>
---
 guix/build/utils.scm | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/guix/build/utils.scm b/guix/build/utils.scm
index ce7bdb2024..5ea3b98353 100644
--- a/guix/build/utils.scm
+++ b/guix/build/utils.scm
@@ -3,11 +3,11 @@
 ;;; Copyright © 2013 Andreas Enge <andreas <at> enge.fr>
 ;;; Copyright © 2013 Nikita Karetnikov <nikita <at> karetnikov.org>
 ;;; Copyright © 2015, 2018, 2021 Mark H Weaver <mhw <at> netris.org>
-;;; Copyright © 2018 Arun Isaac <arunisaac <at> systemreboot.net>
+;;; Copyright © 2018, 2022 Arun Isaac <arunisaac <at> systemreboot.net>
 ;;; Copyright © 2018, 2019 Ricardo Wurmus <rekado <at> elephly.net>
 ;;; Copyright © 2020 Efraim Flashner <efraim <at> flashner.co.il>
 ;;; Copyright © 2020, 2021 Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
-;;; Copyright © 2021 Maxime Devos <maximedevos <at> telenet.be>
+;;; Copyright © 2021, 2022 Maxime Devos <maximedevos <at> telenet.be>
 ;;; Copyright © 2021 Brendan Tildesley <mail <at> brendan.scot>
 ;;;
 ;;; This file is part of GNU Guix.
@@ -245,7 +245,19 @@ (define (switch-symlinks link target)
   "Atomically switch LINK, a symbolic link, to point to TARGET.  Works
 both when LINK already exists and when it does not."
   (let ((pivot (string-append link ".new")))
-    (symlink target pivot)
+    ;; Create pivot link, deleting it if it already exists. This can
+    ;; happen if a previous switch-symlinks was interrupted.
+    (let symlink/remove-old ()
+      (catch 'system-error
+        (lambda ()
+          (symlink target pivot))
+        (lambda args
+          (if (= (system-error-errno args) EEXIST)
+              (begin
+                ;; Remove old link and retry.
+                (delete-file pivot)
+                (symlink/remove-old))
+              (apply throw args)))))
     (rename-file pivot link)))
 
 (define (call-with-temporary-output-file proc)
-- 
2.36.1





This bug report was last modified 3 years and 23 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.