Subject: bug#77402: 31.0.50; Tramp: file-writable-p broken

From: Michael Albinus <[email-masked]>
Date: Mon, 31 Mar 2025 13:17:39 +0200

Gerd Möllmann <[email-masked]> writes:

Hi Gerd,

>>> Hmm, I cannot reproduce the problem. Recipe:
>>>
>>> (make-directory "/ssh:ford:/tmp/yyy")
>>> => nil
>>>
>>> (make-symbolic-link "/tmp/yyy" "/ssh:ford:/tmp/xxx")
>>> => t
>>>
>>> (let ((default-directory "/ssh:ford:/tmp/"))
>>>   (shell-command-to-string "ls -al"))
>>> => "...
>>> lrwxrwxrwx   1 admin    administrators       8 2025-03-31 11:03 xxx -> /tmp/yyy
>>> drwxr-xr-x   2 admin    administrators      40 2025-03-31 11:02 yyy
>>> "
>>>
>>> (file-writable-p "/ssh:ford:/tmp/xxx")
>>> => t
>>>
>>> My local and the remote machine are running GNU/Linux.
>>>
>>> Could you, pls, send the whole Tramp debug buffer with tramp-verbose 6,
>>> after starting a new Emacs session?
>>>
>>> Best regards, Michael.
>>
>> This is with master 1ed1cc83491311517ba46dff73fdc4383ffd4102. I started
>> Emacs without -Q to get Magit, hope that doesn't matter. Settings
>> related to Tramp in my init.el:
>>
>>   (use-package tramp
>>     :defer t
>>     :custom
>>     (auto-revert-remote-files t)
>>
>>     :config
>>     ;; Define profile for a remote zsh connection.
>>     (connection-local-set-profile-variables
>>      'remote-zsh-arm
>>      '((explicit-shell-file-name . "/opt/homebrew/bin/zsh")
>>        (explicit-zsh-args . ("-i"))))
>>
>>     ;; Define which profile to use depending on a connection protocol
>>     ;; and machine. No longer really used since the x86 machine died.
>>     (connection-local-set-profiles '(:protocol "ssh" :machine "pro2") 'remote-zsh-arm)
>>     (connection-local-set-profiles '(:protocol "ssh" :machine "mini") 'remote-zsh-arm)
>>
>>     ;; Let me use my own PATH.
>>     (add-to-list 'tramp-remote-path 'tramp-own-remote-path))
>>
>> Started a fresh Emacs, then
>>
>>   (setq tramp-verbose 6)
>>   M-x magit-status RET /ssh:mini:emacs/github/master RET
>>
>> Status buffer is displayed. Then pulled with "P p" which gives the error
>> "... /tmp.not accessible". Please find the debug buffer contents
>> attached.
>
> Perhaps let me add how it looks in the file system
>
>  gerd@mini 2025-03-31 11:39 
> ~ % ls -ld /tmp
> lrwxr-xr-x@ 1 root  wheel  11 Mar  6 11:06 /tmp -> private/tmp
>  gerd@mini 2025-03-31 11:39 
> ~ % ls -ld /private/tmp
> drwxrwxrwt  6 root  wheel  192 Mar 31 06:55 /private/tmp
>  gerd@mini 2025-03-31 11:40 

Thanks. I went through the debug buffer, and perhaps I found the guilty
place. Could you, please try the attached patch?

If that doesn't work, I need more traces. Higher debug level, and
everything from the beginning. So could you pls call a fresh Emacs like

--8<---------------cut here---------------start------------->8---
# emacs -l tramp --eval '(setq tramp-verbose 10)'
--8<---------------cut here---------------end--------------->8---

Then you can continue with your recipe.

Best regards, Michael.

diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 91ba71510e1..c101f0fb26c 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -4372,9 +4372,7 @@ tramp-handle-file-readable-p
 	  ;; `tramp-check-cached-permissions' doesn't handle symbolic
 	  ;; links.
 	  (and-let* ((symlink (file-symlink-p filename))
-		     ((stringp symlink))
-		     ((file-readable-p
-		       (concat (file-remote-p filename) symlink)))))))))
+		     ((file-readable-p (file-truename filename)))))))))

 (defun tramp-handle-file-regular-p (filename)
   "Like `file-regular-p' for Tramp files."