diff options
author | Ludovic Courtès <ludo@gnu.org> | 2015-10-26 22:17:25 +0100 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2015-10-27 00:01:20 +0100 |
commit | 3bb168b0997d2ba2ef15e8eef2890582c8a6df9c (patch) | |
tree | eb401c746e776bf079764502d7721043f44793de /guix/utils.scm | |
parent | 65797bfffd1b4d9126f11ffb6b59a1a7a18d48f0 (diff) | |
download | guix-patches-3bb168b0997d2ba2ef15e8eef2890582c8a6df9c.tar guix-patches-3bb168b0997d2ba2ef15e8eef2890582c8a6df9c.tar.gz |
utils: Add 'switch-symlinks', moved from (guix ui).
* guix/ui.scm (switch-symlinks): Move to...
* guix/utils.scm: ... here. New procedure.
* guix/scripts/pull.scm: Use it.
Diffstat (limited to 'guix/utils.scm')
-rw-r--r-- | guix/utils.scm | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/guix/utils.scm b/guix/utils.scm index f1317ac756..1542e86f7a 100644 --- a/guix/utils.scm +++ b/guix/utils.scm @@ -74,6 +74,7 @@ arguments-from-environment-variable file-extension file-sans-extension + switch-symlinks call-with-temporary-output-file call-with-temporary-directory with-atomic-file-output @@ -557,6 +558,13 @@ minor version numbers from version-string." (substring file 0 dot) file))) +(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* (string-replace-substring str substr replacement #:optional (start 0) |