From 69beabe287efd40a168aca1ba3c64baba705ae4e Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 16 May 2021 14:01:06 -0400 Subject: [PATCH] Fix #5060: don't hash relative backup file paths Also refactors undo-fu-session's make-hashed-file-path advise to use make-backup-file-name-1. --- core/core-editor.el | 19 +++++++++++++++---- modules/emacs/undo/config.el | 12 +++++++++--- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/core/core-editor.el b/core/core-editor.el index bd0fcb89ef8..4822b6df54f 100644 --- a/core/core-editor.el +++ b/core/core-editor.el @@ -154,11 +154,22 @@ or file path may exist now." ;; HACK Does the same for Emacs backup files, but also packages that use ;; `make-backup-file-name-1' directly (like undo-tree). -(defadvice! doom-make-hashed-backup-file-name-a (args) +(defadvice! doom-make-hashed-backup-file-name-a (orig-fn file) "A few places use the backup file name so paths don't get too long." - :filter-args #'make-backup-file-name-1 - (setcar args (sha1 (car args))) - args) + :around #'make-backup-file-name-1 + (let ((alist backup-directory-alist) + backup-directory) + (while alist + (let ((elt (pop alist))) + (if (string-match (car elt) file) + (setq backup-directory (cdr elt) + alist nil)))) + (let ((file (funcall orig-fn file))) + (if (or (null backup-directory) + (not (file-name-absolute-p backup-directory))) + file + (expand-file-name (sha1 (file-name-nondirectory file)) + (file-name-directory file)))))) ;; diff --git a/modules/emacs/undo/config.el b/modules/emacs/undo/config.el index 31deb4d2d0d..2c84ba4c652 100644 --- a/modules/emacs/undo/config.el +++ b/modules/emacs/undo/config.el @@ -31,10 +31,16 @@ :config (setq undo-fu-session-incompatible-files '("\\.gpg$" "/COMMIT_EDITMSG\\'" "/git-rebase-todo\\'")) - ;; HACK Fix #4993: prevent file names that are too long for the filesystem. + ;; HACK Fix #4993: we've advised `make-backup-file-name-1' to produced SHA1'ed + ;; filenames to prevent file paths that are too long, so we force + ;; `undo-fu-session--make-file-name' to use it instead of its own + ;; home-grown overly-long-filename generator. ;; TODO PR this upstream; should be a universal issue - (advice-add #'undo-fu-session--make-file-name - :filter-args #'doom-make-hashed-backup-file-name-a) + (defadvice! +undo-fu-make-hashed-session-file-name-a (file) + :override #'undo-fu-session--make-file-name + (let ((backup-directory-alist `(("." . ,undo-fu-session-directory)))) + (concat (make-backup-file-name-1 file) + (if undo-fu-session-compression ".gz" ".el")))) ;; HACK Use the faster zstd to compress undo files instead of gzip (when (executable-find "zstd")