From: Paul Eggert Date: Fri, 11 Jul 2025 22:33:26 +0000 (-0700) Subject: Fix (find-file "/dev/null") X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=dce99f6a9861a71bc8bc300195651be64c540485;p=emacs.git Fix (find-file "/dev/null") * lisp/files.el (find-file-noselect-1): When the file exists, propagate any errors signaled by insert-file-contents, instead of propagating them only when the file is unreadable. This way, (find-file "/dev/null") gives a sensible diagnostic "not a regular file" instead of the nonsense "Maximum buffer size exceeded". (cherry picked from commit b911029f96b14a03398198d5a849d6f4d0d1e071) --- diff --git a/lisp/files.el b/lisp/files.el index b335d8d9651..3885637ed58 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -2671,27 +2671,29 @@ Do you want to revisit the file normally now? ")) (and (not rawfile) (set-buffer-multibyte t)) (if rawfile - (condition-case () + (condition-case err (let ((inhibit-read-only t) (enable-local-variables nil)) (insert-file-contents-literally filename t)) (file-error - (when (and (file-exists-p filename) - (not (file-readable-p filename))) + (when (file-exists-p filename) (kill-buffer buf) - (signal 'file-error (list "File is not readable" - filename))) + (signal 'file-error + (if (file-readable-p filename) + (cdr err) + (list "File is not readable" filename)))) ;; Unconditionally set error (setq error t))) - (condition-case () + (condition-case err (let ((inhibit-read-only t)) (insert-file-contents filename t)) (file-error - (when (and (file-exists-p filename) - (not (file-readable-p filename))) + (when (file-exists-p filename) (kill-buffer buf) - (signal 'file-error (list "File is not readable" - filename))) + (signal 'file-error + (if (file-readable-p filename) + (cdr err) + (list "File is not readable" filename)))) ;; Run find-file-not-found-functions until one returns non-nil. (or (run-hook-with-args-until-success 'find-file-not-found-functions) ;; If they fail too, set error.