[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
02/02: inferior: Use a safe symlink monadic procedure.
From: |
guix-commits |
Subject: |
02/02: inferior: Use a safe symlink monadic procedure. |
Date: |
Wed, 10 Mar 2021 07:10:15 -0500 (EST) |
mothacehe pushed a commit to branch master
in repository guix.
commit a831ff6bc3f92ab4ecf6135e4d6386f14189ad06
Author: Mathieu Othacehe <othacehe@gnu.org>
AuthorDate: Wed Mar 10 12:08:10 2021 +0100
inferior: Use a safe symlink monadic procedure.
This is a follow-up of 6ee7e3d26b8f5d2a234518cc2ab1bfeba7cd7c18.
* guix/inferior.scm (cached-channel-instance): Introduce "symlink/safe" and
use it instead of symlink. Remove the duplicated "file-exists?" call.
---
guix/inferior.scm | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/guix/inferior.scm b/guix/inferior.scm
index 259be3f..f977f83 100644
--- a/guix/inferior.scm
+++ b/guix/inferior.scm
@@ -740,8 +740,16 @@ determines whether CHANNELS are authenticated."
(string-append directory "/" file))
(scandir directory base32-encoded-sha256?)))
+ (define (symlink/safe old new)
+ (catch 'system-error
+ (lambda ()
+ (symlink old new))
+ (lambda args
+ (unless (= EEXIST (system-error-errno args))
+ (apply throw args)))))
+
(define symlink*
- (lift2 symlink %store-monad))
+ (lift2 symlink/safe %store-monad))
(define add-indirect-root*
(store-lift add-indirect-root))
@@ -766,9 +774,8 @@ determines whether CHANNELS are authenticated."
(built-derivations (list profile))
;; Note: Caching is fine even when AUTHENTICATE? is false because
;; we always call 'latest-channel-instances?'.
- (unless (file-exists? cached)
- (symlink* (derivation->output-path profile) cached)
- (add-indirect-root* cached))
+ (symlink* (derivation->output-path profile) cached)
+ (add-indirect-root* cached)
(return cached))))))
(define* (inferior-for-channels channels