From 288b6dc962d76412a2c7db825d7dadc829945460 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Wed, 11 Sep 2024 20:02:34 -0400 Subject: [PATCH] fix(cli): doom run: symlinks to XDG dirs beyond $HOME The targets for $XDG_*_HOME symlinks weren't created correctly if they were set to an absolute path outside of the user's $HOME. Fix: #8062 --- lisp/cli/run.el | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lisp/cli/run.el b/lisp/cli/run.el index 1d4699056..8819f3e3c 100644 --- a/lisp/cli/run.el +++ b/lisp/cli/run.el @@ -43,7 +43,7 @@ performance, it is best to run Doom out of ~/.config/emacs or ~/.emacs.d." ;; Evaluate piped-in text directly, if given. (eval (read input) t) (doom-run-repl context)) - (let* ((tempdir (doom-path (temporary-file-directory) "doom.run")) + (let* ((tempdir (doom-path (temporary-file-directory) "doom.run")) (tempemacsdir (doom-path tempdir ".emacs.d"))) (delete-directory tempdir t) ; start from scratch (make-directory tempemacsdir t) @@ -51,18 +51,20 @@ performance, it is best to run Doom out of ~/.config/emacs or ~/.emacs.d." ;; configs, or binscripts, we symlink these to the sandbox. ;; REVIEW: Use `--init-directory' when we drop 29 support OR when Doom is ;; in bootloader mode. - (dolist (dir (list (or (getenv "XDG_DATA_HOME") "~/.local/share") - (or (getenv "XDG_BIN_HOME") "~/.local/bin") - (or (getenv "XDG_CONFIG_HOME") "~/.config") - (or (getenv "XDG_CACHE_HOME") "~/.cache"))) - (let* ((xdg-dir (doom-path dir)) - (target (doom-path tempdir (file-relative-name xdg-dir "~")))) - (when (file-directory-p xdg-dir) + (dolist (dir (list (cons "XDG_DATA_HOME" ".local/share") + (cons "XDG_STATE_HOME" ".local/state") + (cons "XDG_BIN_HOME" ".local/bin") + (cons "XDG_CONFIG_HOME" ".config") + (cons "XDG_CACHE_HOME" ".cache"))) + (let* ((source (expand-file-name (or (getenv (car dir)) (expand-file-name (cdr dir) "~")))) + (target (expand-file-name (cdr dir) tempdir))) + (when (file-directory-p source) (unless (file-symlink-p target) (make-directory (file-name-directory target) t) - (make-symbolic-link xdg-dir target))))) + (make-symbolic-link source target))))) (with-temp-file (doom-path tempemacsdir "early-init.el") (prin1 `(progn + ;; Restore sane values for these envvars (setenv "HOME" ,(getenv "HOME")) (setenv "EMACSDIR" ,doom-emacs-dir) (setenv "DOOMDIR" ,doom-user-dir)