home: symlink-manager: Rename "path" to "file" where appropriate.

* gnu/home/services/symlink-manager.scm (update-symlinks-script):
[home-path]: Rename to...
[home-directory]: ... this.  Adjust users.
[backup-dir]: Rename to...
[backup-directory]: ... this.  Adjust user.
[get-target-path]: Rename to...
[target-file]: ... this.  Adjust users.
[get-backup-path]: Remove.
[backup-file]: Inline it.
[cleanup-symlinks](get-source-path): Rename to...
(source-file): ... this.  Adjust users.
Rename 'he-path' to 'home' and 'new-he-path' to 'pivot'.
This commit is contained in:
Ludovic Courtès 2022-02-26 22:40:04 +01:00
parent 1fb6ef0473
commit 2a55f99aff
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5

View file

@ -48,33 +48,35 @@ (define (update-symlinks-script)
(guix i18n) (guix i18n)
(guix build utils)) (guix build utils))
(define home-path (define home-directory
(getenv "HOME")) (getenv "HOME"))
(define backup-dir (define backup-directory
(string-append home-path "/" (number->string (current-time)) (string-append home-directory "/" (number->string (current-time))
"-guix-home-legacy-configs-backup")) "-guix-home-legacy-configs-backup"))
(define (get-target-path path) (define (target-file file)
(string-append home-path "/." path)) ;; Return the target of FILE, a config file name sans leading dot
;; such as "config/fontconfig/fonts.conf" or "bashrc".
(string-append home-directory "/." file))
(define (get-backup-path path) (define (symlink-to-store? file)
(string-append backup-dir "/." path))
(define (symlink-to-store? path)
(catch 'system-error (catch 'system-error
(lambda () (lambda ()
(store-file-name? (readlink path))) (store-file-name? (readlink file)))
(lambda args (lambda args
(if (= EINVAL (system-error-errno args)) (if (= EINVAL (system-error-errno args))
#f #f
(apply throw args))))) (apply throw args)))))
(define (backup-file path) (define (backup-file file)
(mkdir-p backup-dir) (define backup
(format #t (G_ "Backing up ~a...") (get-target-path path)) (string-append backup-directory "/." file))
(mkdir-p (dirname (get-backup-path path)))
(rename-file (get-target-path path) (get-backup-path path)) (mkdir-p backup-directory)
(format #t (G_ "Backing up ~a...") (target-file file))
(mkdir-p (dirname backup))
(rename-file (target-file file) backup)
(display (G_ " done\n"))) (display (G_ " done\n")))
(define (cleanup-symlinks home-generation) (define (cleanup-symlinks home-generation)
@ -95,7 +97,7 @@ (define (strip file)
(file-system-fold (file-system-fold
(const #t) (const #t)
(lambda (file stat _) ;leaf (lambda (file stat _) ;leaf
(let ((file (get-target-path (strip file)))) (let ((file (target-file (strip file))))
(when (file-exists? file) (when (file-exists? file)
;; DO NOT remove the file if it is no longer a symlink to ;; DO NOT remove the file if it is no longer a symlink to
;; the store, it will be backed up later during ;; the store, it will be backed up later during
@ -112,7 +114,7 @@ (define (strip file)
(const #t) ;down (const #t) ;down
(lambda (directory stat _) ;up (lambda (directory stat _) ;up
(unless (string=? directory config-file-directory) (unless (string=? directory config-file-directory)
(let ((directory (get-target-path (strip directory)))) (let ((directory (target-file (strip directory))))
(catch 'system-error (catch 'system-error
(lambda () (lambda ()
(rmdir directory) (rmdir directory)
@ -145,14 +147,14 @@ (define (strip file)
(string-drop file (string-drop file
(+ 1 (string-length config-file-directory)))) (+ 1 (string-length config-file-directory))))
(define (get-source-path path) (define (source-file file)
(readlink (string-append config-file-directory path))) (readlink (string-append config-file-directory file)))
(file-system-fold (file-system-fold
(const #t) ;enter? (const #t) ;enter?
(lambda (file stat result) ;leaf (lambda (file stat result) ;leaf
(let ((source (get-source-path (strip file))) (let ((source (source-file (strip file)))
(target (get-target-path (strip file)))) (target (target-file (strip file))))
(when (file-exists? target) (when (file-exists? target)
(backup-file (strip file))) (backup-file (strip file)))
(format #t (G_ "Symlinking ~a -> ~a...") (format #t (G_ "Symlinking ~a -> ~a...")
@ -161,7 +163,7 @@ (define (get-source-path path)
(display (G_ " done\n")))) (display (G_ " done\n"))))
(lambda (directory stat result) ;down (lambda (directory stat result) ;down
(unless (string=? directory config-file-directory) (unless (string=? directory config-file-directory)
(let ((target (get-target-path (strip directory)))) (let ((target (target-file (strip directory))))
(when (and (file-exists? target) (when (and (file-exists? target)
(not (file-is-directory? target))) (not (file-is-directory? target)))
(backup-file (strip directory))) (backup-file (strip directory)))
@ -183,18 +185,17 @@ (define (get-source-path path)
#$%initialize-gettext #$%initialize-gettext
(let* ((he-path (string-append (getenv "HOME") "/.guix-home")) (let* ((home (string-append (getenv "HOME") "/.guix-home"))
(new-he-path (string-append he-path ".new")) (pivot (string-append home ".new"))
(new-home (getenv "GUIX_NEW_HOME")) (new-home (getenv "GUIX_NEW_HOME"))
(old-home (getenv "GUIX_OLD_HOME"))) (old-home (getenv "GUIX_OLD_HOME")))
(when old-home (when old-home
(cleanup-symlinks old-home)) (cleanup-symlinks old-home))
(create-symlinks new-home) (create-symlinks new-home)
(symlink new-home new-he-path) (symlink new-home pivot)
(rename-file new-he-path he-path) (rename-file pivot home)
(display (G_" done\nFinished updating symlinks.\n\n"))))))) (display (G_" done\nFinished updating symlinks.\n\n")))))))