unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Arun Isaac <arunisaac@systemreboot.net>
To: 55941@debbugs.gnu.org, Maxime Devos <maximedevos@telenet.be>
Cc: Arun Isaac <arunisaac@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	[thread overview]
Message-ID: <20220613121523.20327-2-arunisaac@systemreboot.net> (raw)
In-Reply-To: <20220613121523.20327-1-arunisaac@systemreboot.net>

* guix/build/utils.scm (switch-symlinks): Delete pivot link if it already
exists.

Co-authored-by: Maxime Devos <maximedevos@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@enge.fr>
 ;;; Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org>
 ;;; Copyright © 2015, 2018, 2021 Mark H Weaver <mhw@netris.org>
-;;; Copyright © 2018 Arun Isaac <arunisaac@systemreboot.net>
+;;; Copyright © 2018, 2022 Arun Isaac <arunisaac@systemreboot.net>
 ;;; Copyright © 2018, 2019 Ricardo Wurmus <rekado@elephly.net>
 ;;; Copyright © 2020 Efraim Flashner <efraim@flashner.co.il>
 ;;; Copyright © 2020, 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
-;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be>
+;;; Copyright © 2021, 2022 Maxime Devos <maximedevos@telenet.be>
 ;;; Copyright © 2021 Brendan Tildesley <mail@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





  reply	other threads:[~2022-06-13 12:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-13 12:13 [bug#55941] [PATCH core-updates 0/3] Move switch-symlinks to (guix build utils) Arun Isaac
2022-06-13 12:15 ` [bug#55941] [PATCH core-updates 1/3] utils: " Arun Isaac
2022-06-13 12:15   ` Arun Isaac [this message]
2022-06-13 12:15   ` [bug#55941] [PATCH core-updates 3/3] services: pcscd: Use switch-symlinks from " Arun Isaac
2022-06-23 20:46 ` [bug#55941] [PATCH core-updates 0/3] Move switch-symlinks to " Ludovic Courtès
2022-06-24 20:30   ` bug#55941: " Arun Isaac

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220613121523.20327-2-arunisaac@systemreboot.net \
    --to=arunisaac@systemreboot.net \
    --cc=55941@debbugs.gnu.org \
    --cc=maximedevos@telenet.be \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).