From 2c05a6112b40c85dd0509052a6a6b97fa127f1c6 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Mon, 13 Jun 2022 16:57:40 +0530 Subject: utils: Move switch-symlinks to (guix build utils). * guix/utils.scm (switch-symlinks): Move to ... * guix/build/utils.scm (switch-symlinks): ... here. * guix/profiles.scm, guix/scripts/home.scm, guix/scripts/package.scm: Import switch-symlinks from (guix build utils). * guix/scripts/system/reconfigure.scm (switch-system-program): Import (guix build utils) in G-expression. --- guix/build/utils.scm | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'guix/build') 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 @@ (define-module (guix build utils) 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 @@ (define (symbolic-link? file) "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 -- cgit v1.2.3