branch: elpa/age
commit 849b8592bac9ff2d2736302c77e304e499693f91
Author: Bas Alberts <[email protected]>
Commit: Bas Alberts <[email protected]>
fix bug in remote TRAMP saving
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.
---
age.el | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/age.el b/age.el
index c34b265f2ac..4cf91313a96 100644
--- a/age.el
+++ b/age.el
@@ -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