Fix issue with find-file-magic-files-alist and TRAMP
authorSteve Youngs <steve@sxemacs.org>
Fri, 27 Mar 2020 11:53:46 +0000 (21:53 +1000)
committerSteve Youngs <steve@sxemacs.org>
Fri, 27 Mar 2020 11:53:46 +0000 (21:53 +1000)
This prevents #'find-file-find-magic from trying to feed #'magic:file a
TRAMP filename.  In the past this wasn't an issue because #'magic:file did
not report errors from the shell or libmagic, it just silently returned
nil.  Not so anymore.

* lisp/files.el (find-file-find-magic): Return 'nil' if it is a
TRAMP filename.

Signed-off-by: Steve Youngs <steve@sxemacs.org>
lisp/files.el

index 3a3028e..ffa0c42 100644 (file)
@@ -1101,10 +1101,13 @@ conversion, find-file-hooks, automatic uncompression, etc.
 
 (defun find-file-find-magic (filename)
   "Find entry in `find-file-magic-files-alist' that matches FILENAME."
-  (find filename find-file-magic-files-alist :key #'car
-       :test #'(lambda (fn predicate)
-                 (and (file-exists-p fn)
-                      (funcall predicate fn)))))
+  ;; Guard against TRAMP filenames, they're incompatible with
+  ;; #'magic:file.
+  (unless (string-match "^/\\[" filename)
+    (find filename find-file-magic-files-alist :key #'car
+         :test #'(lambda (fn predicate)
+                   (and (file-exists-p fn)
+                        (funcall predicate fn))))))
 
 ;;; Sync: XEmacs 21.5 (cb65bfaf7110 tip) 2015-07-03 --SY
 (defcustom find-file-wildcards t