Subject: bug#60943: 28.2; ‘tramp-handle-file-regular-p’ misses symlinks

From: Michael Albinus <[email-masked]>
Date: Thu, 19 Jan 2023 14:12:24 +0100

Greg Pfeil <[email-masked]> writes:

Hi Greg,

> I was having an issue where .dir-locals.el on remote machines weren’t getting picked up when they were a symlink. Local symlinks worked fine, and remote non-symlinks also worked.
>
> Digging in, ‘tramp-handle-regular-file-p’ explicitly checks that the first character in ‘file-attribute-mode’ is ?-. However, for symlinks, that character will be ?l.
>
> Modifying ‘dir-locals--all-files’ to check
>
>   (or (file-regular-p f) (file-symlink-p f))
>
> \(which is ostensibly redundant) instead of simply
>
>   (file-regular-p f)

Indeed, there's a bug. Thanks for the report!

> fixes the behavior, since TRAMP will now check with both ‘tramp-handle-file-regular-p’ and ‘tramp-handle-file-symlink-p’. The correct fix is to make ‘tramp-handle-file-regular-p’ match the behavior of ‘file-regular-p’.

The appended patch fixes this. Eli, is it OK to push to the emacs-29 branch?

Best regards, Michael.

diff --git a/lisp/tramp.el b/lisp/tramp.el
index 351def66..f5208cd9 100644
--- a/lisp/tramp.el
+++ b/lisp/tramp.el
@@ -4039,7 +4039,10 @@ Let-bind it when necessary.")
        ;; Sometimes, `file-attributes' does not return a proper value
        ;; even if `file-exists-p' does.
        (when-let ((attr (file-attributes filename)))
-	 (eq ?- (aref (file-attribute-modes attr) 0)))))
+	 (cond
+	  ((eq ?- (aref (file-attribute-modes attr) 0)))
+	  ((eq ?l (aref (file-attribute-modes attr) 0))
+	   (file-regular-p (file-truename filename)))))))

 (defun tramp-handle-file-remote-p (filename &optional identification connected)
   "Like `file-remote-p' for Tramp files."