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

From: Michael Albinus <[email-masked]>
Date: Mon, 31 Mar 2025 15:46:25 +0200

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

Hi Gerd,

>> Thanks. I went through the debug buffer, and perhaps I found the guilty
>> place. Could you, please try the attached patch?
>
> I'm afraid that didn't fix it yet. 

Hmm. I have the impression the problem is due to the sticky bit set in
/private/tmp. Could you, please, check the modified patch?

If it still doesn't work, I need the full traces again, from the
beginning.

Best regards, Michael.

diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index 5e79d4be41e..92f18139add 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -1831,7 +1831,8 @@ tramp-sh-handle-file-writable-p
 	  ;; Examine `file-attributes' cache to see if request can be
 	  ;; satisfied without remote operation.
 	  (if (tramp-use-file-attributes v)
-	      (tramp-check-cached-permissions v ?w)
+	      (or (tramp-check-cached-permissions v ?w)
+                  (tramp-check-cached-permissions v ?t)))
 	    (tramp-run-test v "-w" localname))
 	;; If file doesn't exist, check if directory is writable.
 	(and
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 91ba71510e1..a3901fa0d69 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."
@@ -6480,7 +6478,8 @@ tramp-check-cached-permissions
                        ((eq ?r access) 1)
                        ((eq ?w access) 2)
                        ((eq ?x access) 3)
-                       ((eq ?s access) 3)))
+                       ((eq ?s access) 3)
+                       ((eq ?t access) 3)))
 	      (file-attr (file-attributes (tramp-make-tramp-file-name vec)))
 	      (remote-uid (tramp-get-remote-uid vec 'integer))
 	      (remote-gid (tramp-get-remote-gid vec 'integer)))