fix(cli): doom sync: heuristic for total rebuilds

Fix: #8024
This commit is contained in:
Henrik Lissner 2024-08-26 02:16:03 -04:00
parent c862968f48
commit 80e9263b85
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -73,12 +73,14 @@ OPTIONS:
;; recompiled. This is necessary because Emacs byte-code is not
;; necessarily back/forward compatible across major versions, and many
;; packages bake in hardcoded data at compile-time.
(pcase-let ((`(,old-version . ,old-host) (doom-file-read doom-cli-sync-info-file :by 'read :noerror t))
(pcase-let ((`(,old-version . ,hash)
(doom-file-read doom-cli-sync-info-file :by 'read :noerror t))
(to-rebuild nil))
(when (and old-version (not (equal old-version emacs-version)))
(print! (warn "Emacs version has changed since last sync (from %s to %s)") old-version emacs-version)
(setq to-rebuild t))
(when (and old-host (not (equal old-host (system-name))))
(when (and (integerp hash)
(not (equal hash (doom-sync--system-hash))))
(print! (warn "Your system has changed since last sync"))
(setq to-rebuild t))
(when (and to-rebuild (not rebuild?) (not (doom-cli-context-suppress-prompts-p context)))
@ -101,7 +103,8 @@ OPTIONS:
(run-hooks 'doom-after-sync-hook))
(when (or rebuild? (not (file-exists-p doom-cli-sync-info-file)))
(with-temp-file doom-cli-sync-info-file
(prin1 (cons emacs-version (system-name)) (current-buffer))))
(prin1 (cons emacs-version (doom-sync--system-hash))
(current-buffer))))
t)
(remove-hook 'kill-emacs-hook #'doom-sync--abort-warning-h)))
@ -109,6 +112,9 @@ OPTIONS:
;;
;;; Helpers
(defun doom-sync--system-hash ()
(sxhash (list doom-local-dir system-type system-configuration-features)))
(defun doom-sync--abort-warning-h ()
(print! (warn "Script was abruptly aborted, leaving Doom in an incomplete state!"))
(print! (item "Run 'doom sync' to repair it.")))