From 55cf3088d0075f7d453eecb1e03683de4444eb4f Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Sat, 22 Jun 2024 12:41:25 -0700 Subject: [PATCH] Fix execution of MS-Windows app execution aliases in Eshell * lisp/eshell/esh-ext.el (eshell-script-interpreter): Return nil if we can't actually read the file. --- lisp/eshell/esh-ext.el | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/lisp/eshell/esh-ext.el b/lisp/eshell/esh-ext.el index 3c4deb32601..6fb0579ed14 100644 --- a/lisp/eshell/esh-ext.el +++ b/lisp/eshell/esh-ext.el @@ -299,18 +299,23 @@ eshell-script-interpreter Return nil, or a list of the form: (INTERPRETER [ARGS] FILE)" - (let ((maxlen eshell-command-interpreter-max-length)) - (if (and (file-readable-p file) - (file-regular-p file)) - (with-temp-buffer - (insert-file-contents-literally file nil 0 maxlen) - (if (looking-at "#![ \t]*\\([^ \r\t\n]+\\)\\([ \t]+\\(.+\\)\\)?") - (if (match-string 3) - (list (match-string 1) - (match-string 3) - file) - (list (match-string 1) - file))))))) + (when (and (file-readable-p file) + (file-regular-p file)) + (let ((maxlen eshell-command-interpreter-max-length)) + ;; If we encounter a file error, assume that FILE doesn't have a + ;; shebang. This can happen, for example, with certain kinds of + ;; reparse points like APPEXECLINK on NTFS filesystems (MS-Windows + ;; uses these for "app execution aliases"). + (ignore-error 'file-error + (with-temp-buffer + (insert-file-contents-literally file nil 0 maxlen) + (if (looking-at "#![ \t]*\\([^ \r\t\n]+\\)\\([ \t]+\\(.+\\)\\)?") + (if (match-string 3) + (list (match-string 1) + (match-string 3) + file) + (list (match-string 1) + file)))))))) (defun eshell-find-interpreter (file args &optional no-examine-p) "Find the command interpreter with which to execute FILE. -- 2.25.1