emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 6e70b37: When decrypting non-decrypted files, make epa show the r


From: Lars Ingebrigtsen
Subject: master 6e70b37: When decrypting non-decrypted files, make epa show the raw files
Date: Tue, 4 Aug 2020 15:43:03 -0400 (EDT)

branch: master
commit 6e70b3793b9cb7730ab8a7132aa6e99f1ca13f98
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    When decrypting non-decrypted files, make epa show the raw files
    
    * lisp/epa-file.el (epa-file-insert-file-contents): When trying to
    decrypt a non-decrypted file, just show the bytes from the file
    instead (bug#3829).
---
 lisp/epa-file.el | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/lisp/epa-file.el b/lisp/epa-file.el
index 20043a9..bbd9279 100644
--- a/lisp/epa-file.el
+++ b/lisp/epa-file.el
@@ -151,17 +151,25 @@ encryption is used."
                        (nth 3 error)))
             (let ((exists (file-exists-p local-file)))
               (when exists
-                ;; Hack to prevent find-file from opening empty buffer
-                ;; when decryption failed (bug#6568).  See the place
-                ;; where `find-file-not-found-functions' are called in
-                ;; `find-file-noselect-1'.
-                (setq-local epa-file-error error)
-                (add-hook 'find-file-not-found-functions
-                          'epa-file--find-file-not-found-function
-                          nil t)
-                (epa-display-error context))
-              (signal (if exists 'file-error 'file-missing)
-                      (cons "Opening input file" (cdr error))))))
+                (epa-display-error context)
+                 ;; When the .gpg file isn't an encrypted file (e.g.,
+                 ;; it's a keyring.gpg file instead), then gpg will
+                 ;; say "Unexpected exit" as the error message.  In
+                 ;; that case, just display the bytes.
+                 (if (equal (caddr error) "Unexpected; Exit")
+                     (setq string (with-temp-buffer
+                                    (insert-file-contents-literally local-file)
+                                    (buffer-string)))
+                  ;; Hack to prevent find-file from opening empty buffer
+                  ;; when decryption failed (bug#6568).  See the place
+                  ;; where `find-file-not-found-functions' are called in
+                  ;; `find-file-noselect-1'.
+                  (setq-local epa-file-error error)
+                  (add-hook 'find-file-not-found-functions
+                            'epa-file--find-file-not-found-function
+                            nil t)
+                  (signal (if exists 'file-error 'file-missing)
+                          (cons "Opening input file" (cdr error))))))))
           (set-buffer buf) ;In case timer/filter changed/killed it (bug#16029)!
          (setq-local epa-file-encrypt-to
                       (mapcar #'car (epg-context-result-for



reply via email to

[Prev in Thread] Current Thread [Next in Thread]