diff options
Diffstat (limited to 'lisp/epa-file.el')
-rw-r--r-- | lisp/epa-file.el | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/lisp/epa-file.el b/lisp/epa-file.el index 2bbb0aa6455..95d8423020b 100644 --- a/lisp/epa-file.el +++ b/lisp/epa-file.el @@ -3,6 +3,7 @@ ;; Author: Daiki Ueno <ueno@unixuser.org> ;; Keywords: PGP, GnuPG +;; Package: epa ;; This file is part of GNU Emacs. @@ -66,10 +67,11 @@ way." (cons entry epa-file-passphrase-alist))) (setq passphrase (epa-passphrase-callback-function context - key-id nil)) + key-id + file)) (setcdr entry (copy-sequence passphrase)) passphrase)))) - (epa-passphrase-callback-function context key-id nil))) + (epa-passphrase-callback-function context key-id file))) ;;;###autoload (defun epa-file-handler (operation &rest args) @@ -101,6 +103,14 @@ way." (insert (epa-file--decode-coding-string string (or coding-system-for-read 'undecided))))) +(defvar epa-file-error nil) +(defun epa-file--find-file-not-found-function () + (let ((error epa-file-error)) + (save-window-excursion + (kill-buffer)) + (signal 'file-error + (cons "Opening input file" (cdr error))))) + (defvar last-coding-system-used) (defun epa-file-insert-file-contents (file &optional visit beg end replace) (barf-if-buffer-read-only) @@ -131,6 +141,16 @@ way." (error (if (setq entry (assoc file epa-file-passphrase-alist)) (setcdr entry nil)) + ;; 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'. + (when (file-exists-p local-file) + (make-local-variable 'epa-file-error) + (setq epa-file-error error) + (add-hook 'find-file-not-found-functions + 'epa-file--find-file-not-found-function + nil t)) (signal 'file-error (cons "Opening input file" (cdr error))))) (make-local-variable 'epa-file-encrypt-to) @@ -139,12 +159,17 @@ way." (if (or beg end) (setq string (substring string (or beg 0) end))) (save-excursion - (save-restriction - (narrow-to-region (point) (point)) - (epa-file-decode-and-insert string file visit beg end replace) - (setq length (- (point-max) (point-min)))) - (if replace - (delete-region (point) (point-max))) + ;; If visiting, bind off buffer-file-name so that + ;; file-locking will not ask whether we should + ;; really edit the buffer. + (let ((buffer-file-name + (if visit nil buffer-file-name))) + (save-restriction + (narrow-to-region (point) (point)) + (epa-file-decode-and-insert string file visit beg end replace) + (setq length (- (point-max) (point-min)))) + (if replace + (delete-region (point) (point-max)))) (if visit (set-visited-file-modtime)))) (if (and local-copy |