aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2024-04-06 11:51:31 +0200
committerLudovic Courtès <ludo@gnu.org>2024-04-06 15:14:58 +0200
commit91e1a457b567935784632b3aa0235a7a3b5d35f9 (patch)
tree44148aeb4465d03764b9fc32f11762e2bd042d7d
parent0b941ea0622abe7f9c9f72d9f8a8a5ac845a3920 (diff)
downloadguix-91e1a457b567935784632b3aa0235a7a3b5d35f9.tar.gz
guix-91e1a457b567935784632b3aa0235a7a3b5d35f9.zip
services: guix: Gracefully handle dangling symlink for ‘machines.scm’.
Previously, if /etc/guix/machines.scm was a dangling symlink, it would be kept (because ‘file-exists?’ would return #f) and thus the following ‘symlink’ call would throw with EEXIST. * gnu/services/base.scm (guix-machines-files-installation): Use ‘lstat’ rather than ‘file-exists?’. Change-Id: I07c7eed842dacabbd19ae2a17ac3e59cf26e46b2
-rw-r--r--gnu/services/base.scm15
1 files changed, 8 insertions, 7 deletions
diff --git a/gnu/services/base.scm b/gnu/services/base.scm
index 5104b3d104..3f912225a0 100644
--- a/gnu/services/base.scm
+++ b/gnu/services/base.scm
@@ -1790,13 +1790,14 @@ archive' public keys, with GUIX."
;; If MACHINES-FILE already exists, move it out of the way.
;; Create a backup if it's a regular file: it's likely that the
;; user manually updated it.
- (if (file-exists? machines-file)
- (if (and (symbolic-link? machines-file)
- (store-file-name? (readlink machines-file)))
- (delete-file machines-file)
- (rename-file machines-file
- (string-append machines-file ".bak")))
- (mkdir-p (dirname machines-file)))
+ (let ((stat (false-if-exception (lstat machines-file))))
+ (if stat
+ (if (and (eq? 'symlink (stat:type stat))
+ (store-file-name? (readlink machines-file)))
+ (delete-file machines-file)
+ (rename-file machines-file
+ (string-append machines-file ".bak")))
+ (mkdir-p (dirname machines-file))))
;; Installed the declared machines file.
(symlink #+(scheme-file "machines.scm"
+0200'>2014-07-08services: Update to use the dmd 0.2 API....Ludovic Courtès 2014-06-27system: Add a 'system?' field to user accounts....Ludovic Courtès 2014-05-26services: Add D-Bus and Avahi....Ludovic Courtès