From 2db149539bc7f9720856f1d17f0e7fa9bf735ea1 Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Thu, 24 Feb 2022 16:11:01 +0100 Subject: [PATCH] Fix symlinks in tramp-sshfs.el (Bug#54130) * lisp/net/tramp-sshfs.el (tramp-methods) : Add "-o transform_symlinks" to `tramp-mount-args'. (tramp-sshfs-file-name-handler-alist): Use `tramp-sshfs-handle-file-writable-p'. (tramp-sshfs-handle-file-writable-p): New defun. (Bug#54130) * test/lisp/net/tramp-tests.el (tramp-test18-file-attributes) (tramp-test20-file-modes): Adapt tests. --- lisp/net/tramp-sshfs.el | 9 +++++++-- test/lisp/net/tramp-tests.el | 10 +++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lisp/net/tramp-sshfs.el b/lisp/net/tramp-sshfs.el index d30c19436d5..90b3c2ba2c2 100644 --- a/lisp/net/tramp-sshfs.el +++ b/lisp/net/tramp-sshfs.el @@ -51,10 +51,11 @@ (add-to-list 'tramp-methods `(,tramp-sshfs-method (tramp-mount-args (("-C") ("-p" "%p") + ("-o" "transform_symlinks") ("-o" "idmap=user,reconnect"))) ;; These are for remote processes. (tramp-login-program "ssh") - (tramp-login-args (("-q")("-l" "%u") ("-p" "%p") + (tramp-login-args (("-q") ("-l" "%u") ("-p" "%p") ("-e" "none") ("-t" "-t") ("%h") ("%l"))) (tramp-direct-async t) @@ -119,7 +120,7 @@ (file-symlink-p . tramp-handle-file-symlink-p) (file-system-info . tramp-sshfs-handle-file-system-info) (file-truename . tramp-handle-file-truename) - (file-writable-p . tramp-handle-file-writable-p) + (file-writable-p . tramp-sshfs-handle-file-writable-p) (find-backup-file-name . tramp-handle-find-backup-file-name) ;; `get-file-buffer' performed by default handler. (insert-directory . tramp-handle-insert-directory) @@ -220,6 +221,10 @@ arguments to pass to the OPERATION." ;;`file-system-info' exists since Emacs 27.1. (tramp-compat-funcall 'file-system-info (tramp-fuse-local-file-name filename))) +(defun tramp-sshfs-handle-file-writable-p (filename) + "Like `file-writable-p' for Tramp files." + (file-writable-p (tramp-fuse-local-file-name filename))) + (defun tramp-sshfs-handle-insert-file-contents (filename &optional visit beg end replace) "Like `insert-file-contents' for Tramp files." diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index 4e74f2aa73f..c468c3501bf 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el @@ -3437,8 +3437,10 @@ This tests also `access-file', `file-readable-p', (should (string-equal (file-attribute-type attr) - (tramp-file-name-localname - (tramp-dissect-file-name tmp-name3)))) + (funcall + (if (tramp--test-sshfs-p) #'file-name-nondirectory #'identity) + (tramp-file-name-localname + (tramp-dissect-file-name tmp-name3))))) (delete-file tmp-name2)) (when test-file-ownership-preserved-p @@ -3598,7 +3600,9 @@ This tests also `file-executable-p', `file-writable-p' and `set-file-modes'." (should (= (file-modes tmp-name1) #o444)) (should-not (file-executable-p tmp-name1)) ;; A file is always writable for user "root". - (unless (zerop (file-attribute-user-id (file-attributes tmp-name1))) + (unless + (or (zerop (file-attribute-user-id (file-attributes tmp-name1))) + (tramp--test-sshfs-p)) (should-not (file-writable-p tmp-name1))) ;; Check the NOFOLLOW arg. It exists since Emacs 28. For ;; regular files, there shouldn't be a difference. -- 2.39.5