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.
This commit is contained in:
Henrik Lissner 2021-05-16 14:01:06 -04:00
parent 62c231efe6
commit 69beabe287
2 changed files with 24 additions and 7 deletions

View file

@ -154,11 +154,22 @@ or file path may exist now."
;; HACK Does the same for Emacs backup files, but also packages that use ;; HACK Does the same for Emacs backup files, but also packages that use
;; `make-backup-file-name-1' directly (like undo-tree). ;; `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." "A few places use the backup file name so paths don't get too long."
:filter-args #'make-backup-file-name-1 :around #'make-backup-file-name-1
(setcar args (sha1 (car args))) (let ((alist backup-directory-alist)
args) 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))))))
;; ;;

View file

@ -31,10 +31,16 @@
:config :config
(setq undo-fu-session-incompatible-files '("\\.gpg$" "/COMMIT_EDITMSG\\'" "/git-rebase-todo\\'")) (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 ;; TODO PR this upstream; should be a universal issue
(advice-add #'undo-fu-session--make-file-name (defadvice! +undo-fu-make-hashed-session-file-name-a (file)
:filter-args #'doom-make-hashed-backup-file-name-a) :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 ;; HACK Use the faster zstd to compress undo files instead of gzip
(when (executable-find "zstd") (when (executable-find "zstd")