Skip to content

Commit

Permalink
fix bug in remote TRAMP saving
Browse files Browse the repository at this point in the history
Have to disable age file handling in TRAMP encoding/decoding contexts
to prevent accidental decrypts when TRAMP encodes the local age file
contents through it's write-region handler.
  • Loading branch information
anticomputer committed Jan 2, 2023
1 parent 055f7e2 commit 849b859
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions age.el
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,23 @@
(require 'rfc6068)
(eval-when-compile (require 'cl-lib))
(eval-when-compile (require 'subr-x))
(eval-when-compile (require 'tramp-sh))

;;; TRAMP handling advice

;;disable age file handlers on local encoding
(defun age-tramp-sh-handle-write-region-advice (orig-tramp-sh-handle-write-region &rest args)
"This advice disables age file handling in TRAMP region writes.
This prevents TRAMP from triggering age file decryption when inserting local
copies of the file during its write-region encoding. This is similar to how
`epa-file-handler' is inhibited, but since we're not part of emacs we have
to advice TRAMP to ignore `age-file-handler' instead."
(cl-letf (((symbol-value 'file-name-handler-alist)
(remq age-file-handler file-name-handler-alist))
((symbol-value 'auto-mode-alist)
(remq age-file-auto-mode-alist-entry auto-mode-alist)))
(apply orig-tramp-sh-handle-write-region args)))
(advice-add 'tramp-sh-handle-write-region :around #'age-tramp-sh-handle-write-region-advice)

;;; Configuration

Expand Down

0 comments on commit 849b859

Please sign in to comment.