]> git.eshelyaron.com Git - emacs.git/commitdiff
Improve handling of INFILE in tramp*-process-file (Bug#53284)
authorMichael Albinus <michael.albinus@gmx.de>
Mon, 17 Jan 2022 09:46:58 +0000 (10:46 +0100)
committerMichael Albinus <michael.albinus@gmx.de>
Mon, 17 Jan 2022 09:46:58 +0000 (10:46 +0100)
* lisp/net/tramp-adb.el (tramp-adb-handle-process-file):
* lisp/net/tramp-sh.el (tramp-sh-handle-process-file):
* lisp/net/tramp-smb.el (tramp-smb-handle-process-file):
* lisp/net/tramp-sshfs.el (tramp-sshfs-handle-process-file):
Improve handling of INFILE.  Fix thinko using
`process-file-side-effects'.  (Bug#53284)

* lisp/net/tramp-sshfs.el (tramp-sshfs-file-name-handler-alist):
Use `tramp-sshfs-handle-set-file-times'.
(tramp-sshfs-handle-set-file-times): New defun.

* test/lisp/net/tramp-tests.el (tramp-test28-process-file): Extend test.

lisp/net/tramp-adb.el
lisp/net/tramp-sh.el
lisp/net/tramp-smb.el
lisp/net/tramp-sshfs.el
test/lisp/net/tramp-tests.el

index ed73a86ef035caa01b5bc4810aa2ab6b601bbb21..699dec4d58e2772870ee69f7d06dcdebad9080ed 100644 (file)
@@ -815,7 +815,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
       ;; Determine input.
       (if (null infile)
          (setq input (tramp-get-remote-null-device v))
-       (setq infile (expand-file-name infile))
+       (setq infile (tramp-compat-file-name-unquote (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))
@@ -870,7 +870,8 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
              (setq ret (tramp-adb-send-command-and-check
                         v (format
                            "(cd %s; %s)"
-                           (tramp-shell-quote-argument localname) command)
+                           (tramp-unquote-shell-quote-argument localname)
+                           command)
                         t))
            (unless (natnump ret) (setq ret 1))
            ;; We should add the output anyway.
@@ -900,8 +901,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
       ;; 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
+      (when process-file-side-effects
         (tramp-flush-directory-properties v ""))
 
       ;; Return exit status.
index 72b1ebb3e0636b0481184c072d38abf06d1dfae4..ffa11b1fe3c0b331baf261d7550957789ca16820 100644 (file)
@@ -3098,7 +3098,7 @@ implementation will be used."
       ;; Determine input.
       (if (null infile)
          (setq input (tramp-get-remote-null-device v))
-       (setq infile (expand-file-name infile))
+       (setq infile (tramp-compat-file-name-unquote (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))
@@ -3153,7 +3153,8 @@ implementation will be used."
               (setq ret (tramp-send-command-and-check
                         v (format
                            "cd %s && %s"
-                           (tramp-shell-quote-argument localname) command)
+                           (tramp-unquote-shell-quote-argument localname)
+                           command)
                         t t t))
            (unless (natnump ret) (setq ret 1))
            ;; We should add the output anyway.
@@ -3184,8 +3185,7 @@ implementation will be used."
       ;; 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
+      (when process-file-side-effects
         (tramp-flush-directory-properties v ""))
 
       ;; Return exit status.
index c5f423fa3f0dce4c8337b198e4433c35a01b6c35..6515519680c27f1c3b0d4d1be9a229a438b7c8ef 100644 (file)
@@ -1281,7 +1281,7 @@ component is used as the target of the symlink."
 
       ;; Determine input.
       (when infile
-       (setq infile (expand-file-name infile))
+       (setq infile (tramp-compat-file-name-unquote (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))
@@ -1373,8 +1373,7 @@ component is used as the target of the symlink."
       (when tmpinput (delete-file tmpinput))
       (unless outbuf
        (kill-buffer (tramp-get-connection-property v "process-buffer" nil)))
-
-      (unless process-file-side-effects
+      (when process-file-side-effects
        (tramp-flush-directory-properties v ""))
 
       ;; Return exit status.
index 0a5bf2f43b33c99ed31b52c1d2f9805cc36df550..8890d0ec5c3572e6a0fd01d2220cb89208f98d1e 100644 (file)
     (set-file-acl . ignore)
     (set-file-modes . tramp-sshfs-handle-set-file-modes)
     (set-file-selinux-context . ignore)
-    (set-file-times . ignore)
+    (set-file-times . tramp-sshfs-handle-set-file-times)
     (set-visited-file-modtime . tramp-handle-set-visited-file-modtime)
     (shell-command . tramp-handle-shell-command)
     (start-file-process . tramp-handle-start-file-process)
@@ -242,13 +242,28 @@ arguments to pass to the OPERATION."
     (let ((command
           (format
            "cd %s && exec %s"
-           localname
-           (mapconcat #'tramp-shell-quote-argument (cons program args) " "))))
+           (tramp-unquote-shell-quote-argument 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 (tramp-compat-file-name-unquote (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)
-          infile destination display
+          nil destination display
           (tramp-expand-args
            v 'tramp-login-args
            ?h (or (tramp-file-name-host v) "")
@@ -256,7 +271,11 @@ arguments to pass to the OPERATION."
            ?p (or (tramp-file-name-port v) "")
            ?l command))
 
-       (unless process-file-side-effects
+       ;; Cleanup.  We remove all file cache values for the
+       ;; connection, because the remote process could have changed
+       ;; them.
+       (when tmpinput (delete-file tmpinput))
+       (when process-file-side-effects
           (tramp-flush-directory-properties v ""))))))
 
 (defun tramp-sshfs-handle-rename-file
@@ -285,6 +304,15 @@ arguments to pass to the OPERATION."
       (tramp-compat-set-file-modes
        (tramp-fuse-local-file-name filename) mode flag))))
 
+(defun tramp-sshfs-handle-set-file-times (filename &optional timestamp flag)
+  "Like `set-file-times' for Tramp files."
+  (or (file-exists-p filename) (write-region "" nil filename nil 0))
+  (with-parsed-tramp-file-name filename nil
+    (unless (and (eq flag 'nofollow) (file-symlink-p filename))
+      (tramp-flush-file-properties v localname)
+      (tramp-compat-set-file-times
+       (tramp-fuse-local-file-name filename) timestamp flag))))
+
 (defun tramp-sshfs-handle-write-region
   (start end filename &optional append visit lockname mustbenew)
   "Like `write-region' for Tramp files."
index ea0ff3c760e9cd838e70045e825c3286545ab828..a07d749916e01936d797369af82f7889c36cf408 100644 (file)
@@ -4504,7 +4504,19 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
              (should
               (string-equal (format "%s\n%s\n" fnnd fnnd) (buffer-string)))
              ;; A non-nil DISPLAY must not raise the buffer.
-             (should-not (get-buffer-window (current-buffer) t))))
+             (should-not (get-buffer-window (current-buffer) t))
+             (delete-file tmp-name))
+
+           ;; Check remote and local INFILE.
+           (dolist (local '(nil t))
+             (with-temp-buffer
+               (setq tmp-name (tramp--test-make-temp-name local quoted))
+               (write-region "foo" nil tmp-name)
+               (should (file-exists-p tmp-name))
+               (should (zerop (process-file "cat" tmp-name t)))
+               (should (string-equal "foo" (buffer-string)))
+               (should-not (get-buffer-window (current-buffer) t)))
+             (delete-file tmp-name)))
 
        ;; Cleanup.
        (ignore-errors (delete-file tmp-name))))))