Skip to content

Commit

Permalink
Fix doomemacs#5060: don't hash relative backup file paths
Browse files Browse the repository at this point in the history
Also refactors undo-fu-session's make-hashed-file-path advise to use
make-backup-file-name-1.
  • Loading branch information
hlissner committed May 16, 2021
1 parent 62c231e commit 69beabe
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
19 changes: 15 additions & 4 deletions core/core-editor.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))))))


;;
Expand Down
12 changes: 9 additions & 3 deletions modules/emacs/undo/config.el
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 69beabe

Please sign in to comment.