refactor(cli): doctor: extract symlink check to function

This commit is contained in:
Henrik Lissner
2025-04-10 22:45:46 -04:00
parent fb0dc4cc85
commit cbdce0dc71
2 changed files with 36 additions and 29 deletions

View File

@ -184,35 +184,22 @@ in."
(format " (setq-default vterm-shell \"%s\")\n" shell-file-name) (format " (setq-default vterm-shell \"%s\")\n" shell-file-name)
(format " (setq-default explicit-shell-file-name \"%s\")\n" shell-file-name))) (format " (setq-default explicit-shell-file-name \"%s\")\n" shell-file-name)))
(condition-case e (unless (doom-system-supports-symlinks-p)
(when (featurep :system 'windows) (print! (warn "Symlinks are not enabled on this operating system"))
(let ((filea (expand-file-name "__testfile1" temporary-file-directory)) (explain! "In the near future, Doom will make extensive use of symlinks to save space "
(fileb (expand-file-name "__testfile2" temporary-file-directory))) "and simplify package and profile management. Without symlinks, much of it "
(unwind-protect "won't be functional. To get around this, you have three options:"
(progn "\n\n"
(with-temp-file fileb) " - Enabling 'Developer Mode' in the Windows settings (search for 'Developer "
(make-symbolic-link fileb filea) " Settings' in the start menu). This will warn you about its effect on system "
(not (file-symlink-p filea))) " security, but this can be ignored. If it bothers you, consider another option "
(delete-file filea) " below.\n"
(delete-file fileb)))) " - Running your shell (cmd or powershell) in administrator mode anytime you "
('file-error " need to use the 'doom' script. Also, the `doom/reload' command won't work "
(when (equal (cons (nth 1 e) (nth 2 e)) " unless Emacs itself is launched in administrator mode.\n"
(cons "Making symbolic link" "Operation not permitted")) " - Install Emacs in WSL 1/2; the native Linux environment it creates supports "
(print! (warn "Symlinks are not enabled on this operating system")) " symlinks out of the box and is the best option (as Emacs is generally more "
(explain! "In the near future, Doom will make extensive use of symlinks to save space " " stable, predictable, and faster there).\n\n")))
"and simplify package and profile management. Without symlinks, much of it "
"won't be functional. To get around this, you have three options:"
"\n\n"
" - Enabling 'Developer Mode' in the Windows settings (search for 'Developer "
" Settings' in the start menu). This will warn you about its effect on system "
" security, but this can be ignored. If it bothers you, consider another option "
" below.\n"
" - Running your shell (cmd or powershell) in administrator mode anytime you "
" need to use the 'doom' script. Also, the `doom/reload' command won't work "
" unless Emacs itself is launched in administrator mode.\n"
" - Install Emacs in WSL 1/2; the native Linux environment it creates supports "
" symlinks out of the box and is the best option (as Emacs is generally more "
" stable, predictable, and faster there).\n\n")))))
(print! (start "Checking for stale elc files...")) (print! (start "Checking for stale elc files..."))
(elc-check-dir doom-core-dir) (elc-check-dir doom-core-dir)

View File

@ -110,5 +110,25 @@ Tries to be portable. Returns 1 if cannot be determined."
(cdr cpus))))) (cdr cpus)))))
1)))))) 1))))))
;;;###autoload
(defun doom-system-supports-symlinks-p ()
"Return non-nil if this system supports symlinks"
(condition-case e
(let ((filea (expand-file-name "__doom_testfile1" temporary-file-directory))
(fileb (expand-file-name "__doom_testfile2" temporary-file-directory)))
(unwind-protect
(progn
(with-temp-file fileb)
(make-symbolic-link fileb filea)
(and (file-symlink-p filea)
(file-equal-p filea fileb)))
(delete-file filea)
(delete-file fileb)))
(file-error
(if (equal (cons (nth 1 e) (nth 2 e))
(cons "Making symbolic link" "Operation not permitted"))
nil
(signal (car e) (cdr e))))))
(provide 'doom-lib '(system)) (provide 'doom-lib '(system))
;;; system.el ends here ;;; system.el ends here