Subject: Re: bug#53284: 28.0.91; TRAMP SSHFS: process-file with remote input file doesn't work

From: Michael Albinus <[email-masked]>
Date: Sat, 15 Jan 2022 20:42:09 +0100

Philipp Stephani <[email-masked]> writes:

Hi Philipp,

> $ mkdir -p /tmp/tramptest && emacs -Q -batch -l tramp-sshfs -l tramp -eval '(let ((default-directory "/sshfs:localhost:/tmp/tramptest/"))
>   (write-region "hello" nil "input")
>   (with-temp-buffer
>     (print (list (process-file "cat" "input" t)
>                  (buffer-string)))))'
>
> (1 "")
>
> I think the problem is that tramp-sshfs-handle-process-file doesn't pass
> the correct input file to tramp-call-process; it should first expand the
> input file against the remote default directory and then copy it locally
> to pass it to the SSH process.

Could you pls try the appended patch?

Best regards, Michael.

*** /tmp/ediffDAueJg	2022-01-15 20:40:02.604224925 +0100
--- /home/albinus/src/tramp/lisp/tramp-sshfs.el	2022-01-15 20:36:50.765907615 +0100
***************
*** 243,254 ****
  	   (format
  	    "cd %s && exec %s"
  	    localname
! 	    (mapconcat #'tramp-shell-quote-argument (cons program args) " "))))
        (unwind-protect
  	  (apply
  	   #'tramp-call-process
  	   v (tramp-get-method-parameter v 'tramp-login-program)
! 	   infile destination display
  	   (tramp-expand-args
  	    v 'tramp-login-args
  	    ?h (or (tramp-file-name-host v) "")
--- 243,269 ----
  	   (format
  	    "cd %s && exec %s"
  	    localname
! 	    (mapconcat #'tramp-shell-quote-argument (cons program args) " ")))
! 	  input tmpinput)
!
!       ;; Determine input.
!       (if (null infile)
! 	  (setq input (tramp-get-remote-null-device v))
! 	(setq infile (expand-file-name infile))
! 	(if (tramp-equal-remote default-directory infile)
! 	    ;; INFILE is on the same remote host.
! 	    (setq input (tramp-file-local-name infile))
! 	  ;; INFILE must be copied to remote host.
! 	  (setq input (tramp-make-tramp-temp-file v)
! 		tmpinput (tramp-make-tramp-file-name v input 'nohop))
! 	  (copy-file infile tmpinput t)))
!       (when input (setq command (format "%s <%s" command input)))
!
        (unwind-protect
  	  (apply
  	   #'tramp-call-process
  	   v (tramp-get-method-parameter v 'tramp-login-program)
! 	   nil destination display
  	   (tramp-expand-args
  	    v 'tramp-login-args
  	    ?h (or (tramp-file-name-host v) "")
***************
*** 256,261 ****
--- 271,281 ----
  	    ?p (or (tramp-file-name-port v) "")
  	    ?l command))

+ 	;; Cleanup.  We remove all file cache values for the
+ 	;; connection, because the remote process could have changed
+ 	;; them.
+ 	(when tmpinput (delete-file tmpinput))
+
  	(unless process-file-side-effects
            (tramp-flush-directory-properties v ""))))))