summaryrefslogtreecommitdiff
path: root/guix/build
diff options
context:
space:
mode:
Diffstat (limited to 'guix/build')
-rw-r--r--guix/build/utils.scm8
1 files changed, 8 insertions, 0 deletions
diff --git a/guix/build/utils.scm b/guix/build/utils.scm
index b822caf619..ce7bdb2024 100644
--- a/guix/build/utils.scm
+++ b/guix/build/utils.scm
@@ -60,6 +60,7 @@
directory-exists?
executable-file?
symbolic-link?
+ switch-symlinks
call-with-temporary-output-file
call-with-ascii-input-file
file-header-match
@@ -240,6 +241,13 @@ introduce the version part."
"Return #t if FILE is a symbolic link (aka. \"symlink\".)"
(eq? (stat:type (lstat file)) 'symlink))
+(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)
+ (rename-file pivot link)))
+
(define (call-with-temporary-output-file proc)
"Call PROC with a name of a temporary file and open output port to that
file; close the file and delete it when leaving the dynamic extent of this