diff options
| author | Michael Albinus | 2022-01-17 10:46:58 +0100 |
|---|---|---|
| committer | Michael Albinus | 2022-01-17 10:46:58 +0100 |
| commit | c9d06d080bb2bd012813d6e5ac1f3deb32ccb29f (patch) | |
| tree | c1971052479f79da7c286375539eca80fc090999 | |
| parent | 65666c47863c4ad2ed4bacd1a0bc5e638269df52 (diff) | |
| download | emacs-c9d06d080bb2bd012813d6e5ac1f3deb32ccb29f.tar.gz emacs-c9d06d080bb2bd012813d6e5ac1f3deb32ccb29f.zip | |
Improve handling of INFILE in tramp*-process-file (Bug#53284)
* 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.
| -rw-r--r-- | lisp/net/tramp-adb.el | 8 | ||||
| -rw-r--r-- | lisp/net/tramp-sh.el | 8 | ||||
| -rw-r--r-- | lisp/net/tramp-smb.el | 5 | ||||
| -rw-r--r-- | lisp/net/tramp-sshfs.el | 38 | ||||
| -rw-r--r-- | test/lisp/net/tramp-tests.el | 14 |
5 files changed, 56 insertions, 17 deletions
diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el index ed73a86ef03..699dec4d58e 100644 --- a/lisp/net/tramp-adb.el +++ b/lisp/net/tramp-adb.el | |||
| @@ -815,7 +815,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored." | |||
| 815 | ;; Determine input. | 815 | ;; Determine input. |
| 816 | (if (null infile) | 816 | (if (null infile) |
| 817 | (setq input (tramp-get-remote-null-device v)) | 817 | (setq input (tramp-get-remote-null-device v)) |
| 818 | (setq infile (expand-file-name infile)) | 818 | (setq infile (tramp-compat-file-name-unquote (expand-file-name infile))) |
| 819 | (if (tramp-equal-remote default-directory infile) | 819 | (if (tramp-equal-remote default-directory infile) |
| 820 | ;; INFILE is on the same remote host. | 820 | ;; INFILE is on the same remote host. |
| 821 | (setq input (tramp-file-local-name infile)) | 821 | (setq input (tramp-file-local-name infile)) |
| @@ -870,7 +870,8 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored." | |||
| 870 | (setq ret (tramp-adb-send-command-and-check | 870 | (setq ret (tramp-adb-send-command-and-check |
| 871 | v (format | 871 | v (format |
| 872 | "(cd %s; %s)" | 872 | "(cd %s; %s)" |
| 873 | (tramp-shell-quote-argument localname) command) | 873 | (tramp-unquote-shell-quote-argument localname) |
| 874 | command) | ||
| 874 | t)) | 875 | t)) |
| 875 | (unless (natnump ret) (setq ret 1)) | 876 | (unless (natnump ret) (setq ret 1)) |
| 876 | ;; We should add the output anyway. | 877 | ;; We should add the output anyway. |
| @@ -900,8 +901,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored." | |||
| 900 | ;; Cleanup. We remove all file cache values for the connection, | 901 | ;; Cleanup. We remove all file cache values for the connection, |
| 901 | ;; because the remote process could have changed them. | 902 | ;; because the remote process could have changed them. |
| 902 | (when tmpinput (delete-file tmpinput)) | 903 | (when tmpinput (delete-file tmpinput)) |
| 903 | 904 | (when process-file-side-effects | |
| 904 | (unless process-file-side-effects | ||
| 905 | (tramp-flush-directory-properties v "")) | 905 | (tramp-flush-directory-properties v "")) |
| 906 | 906 | ||
| 907 | ;; Return exit status. | 907 | ;; Return exit status. |
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index 72b1ebb3e06..ffa11b1fe3c 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el | |||
| @@ -3098,7 +3098,7 @@ implementation will be used." | |||
| 3098 | ;; Determine input. | 3098 | ;; Determine input. |
| 3099 | (if (null infile) | 3099 | (if (null infile) |
| 3100 | (setq input (tramp-get-remote-null-device v)) | 3100 | (setq input (tramp-get-remote-null-device v)) |
| 3101 | (setq infile (expand-file-name infile)) | 3101 | (setq infile (tramp-compat-file-name-unquote (expand-file-name infile))) |
| 3102 | (if (tramp-equal-remote default-directory infile) | 3102 | (if (tramp-equal-remote default-directory infile) |
| 3103 | ;; INFILE is on the same remote host. | 3103 | ;; INFILE is on the same remote host. |
| 3104 | (setq input (tramp-file-local-name infile)) | 3104 | (setq input (tramp-file-local-name infile)) |
| @@ -3153,7 +3153,8 @@ implementation will be used." | |||
| 3153 | (setq ret (tramp-send-command-and-check | 3153 | (setq ret (tramp-send-command-and-check |
| 3154 | v (format | 3154 | v (format |
| 3155 | "cd %s && %s" | 3155 | "cd %s && %s" |
| 3156 | (tramp-shell-quote-argument localname) command) | 3156 | (tramp-unquote-shell-quote-argument localname) |
| 3157 | command) | ||
| 3157 | t t t)) | 3158 | t t t)) |
| 3158 | (unless (natnump ret) (setq ret 1)) | 3159 | (unless (natnump ret) (setq ret 1)) |
| 3159 | ;; We should add the output anyway. | 3160 | ;; We should add the output anyway. |
| @@ -3184,8 +3185,7 @@ implementation will be used." | |||
| 3184 | ;; Cleanup. We remove all file cache values for the connection, | 3185 | ;; Cleanup. We remove all file cache values for the connection, |
| 3185 | ;; because the remote process could have changed them. | 3186 | ;; because the remote process could have changed them. |
| 3186 | (when tmpinput (delete-file tmpinput)) | 3187 | (when tmpinput (delete-file tmpinput)) |
| 3187 | 3188 | (when process-file-side-effects | |
| 3188 | (unless process-file-side-effects | ||
| 3189 | (tramp-flush-directory-properties v "")) | 3189 | (tramp-flush-directory-properties v "")) |
| 3190 | 3190 | ||
| 3191 | ;; Return exit status. | 3191 | ;; Return exit status. |
diff --git a/lisp/net/tramp-smb.el b/lisp/net/tramp-smb.el index c5f423fa3f0..6515519680c 100644 --- a/lisp/net/tramp-smb.el +++ b/lisp/net/tramp-smb.el | |||
| @@ -1281,7 +1281,7 @@ component is used as the target of the symlink." | |||
| 1281 | 1281 | ||
| 1282 | ;; Determine input. | 1282 | ;; Determine input. |
| 1283 | (when infile | 1283 | (when infile |
| 1284 | (setq infile (expand-file-name infile)) | 1284 | (setq infile (tramp-compat-file-name-unquote (expand-file-name infile))) |
| 1285 | (if (tramp-equal-remote default-directory infile) | 1285 | (if (tramp-equal-remote default-directory infile) |
| 1286 | ;; INFILE is on the same remote host. | 1286 | ;; INFILE is on the same remote host. |
| 1287 | (setq input (tramp-file-local-name infile)) | 1287 | (setq input (tramp-file-local-name infile)) |
| @@ -1373,8 +1373,7 @@ component is used as the target of the symlink." | |||
| 1373 | (when tmpinput (delete-file tmpinput)) | 1373 | (when tmpinput (delete-file tmpinput)) |
| 1374 | (unless outbuf | 1374 | (unless outbuf |
| 1375 | (kill-buffer (tramp-get-connection-property v "process-buffer" nil))) | 1375 | (kill-buffer (tramp-get-connection-property v "process-buffer" nil))) |
| 1376 | 1376 | (when process-file-side-effects | |
| 1377 | (unless process-file-side-effects | ||
| 1378 | (tramp-flush-directory-properties v "")) | 1377 | (tramp-flush-directory-properties v "")) |
| 1379 | 1378 | ||
| 1380 | ;; Return exit status. | 1379 | ;; Return exit status. |
diff --git a/lisp/net/tramp-sshfs.el b/lisp/net/tramp-sshfs.el index 0a5bf2f43b3..8890d0ec5c3 100644 --- a/lisp/net/tramp-sshfs.el +++ b/lisp/net/tramp-sshfs.el | |||
| @@ -137,7 +137,7 @@ | |||
| 137 | (set-file-acl . ignore) | 137 | (set-file-acl . ignore) |
| 138 | (set-file-modes . tramp-sshfs-handle-set-file-modes) | 138 | (set-file-modes . tramp-sshfs-handle-set-file-modes) |
| 139 | (set-file-selinux-context . ignore) | 139 | (set-file-selinux-context . ignore) |
| 140 | (set-file-times . ignore) | 140 | (set-file-times . tramp-sshfs-handle-set-file-times) |
| 141 | (set-visited-file-modtime . tramp-handle-set-visited-file-modtime) | 141 | (set-visited-file-modtime . tramp-handle-set-visited-file-modtime) |
| 142 | (shell-command . tramp-handle-shell-command) | 142 | (shell-command . tramp-handle-shell-command) |
| 143 | (start-file-process . tramp-handle-start-file-process) | 143 | (start-file-process . tramp-handle-start-file-process) |
| @@ -242,13 +242,28 @@ arguments to pass to the OPERATION." | |||
| 242 | (let ((command | 242 | (let ((command |
| 243 | (format | 243 | (format |
| 244 | "cd %s && exec %s" | 244 | "cd %s && exec %s" |
| 245 | localname | 245 | (tramp-unquote-shell-quote-argument localname) |
| 246 | (mapconcat #'tramp-shell-quote-argument (cons program args) " ")))) | 246 | (mapconcat #'tramp-shell-quote-argument (cons program args) " "))) |
| 247 | input tmpinput) | ||
| 248 | |||
| 249 | ;; Determine input. | ||
| 250 | (if (null infile) | ||
| 251 | (setq input (tramp-get-remote-null-device v)) | ||
| 252 | (setq infile (tramp-compat-file-name-unquote (expand-file-name infile))) | ||
| 253 | (if (tramp-equal-remote default-directory infile) | ||
| 254 | ;; INFILE is on the same remote host. | ||
| 255 | (setq input (tramp-file-local-name infile)) | ||
| 256 | ;; INFILE must be copied to remote host. | ||
| 257 | (setq input (tramp-make-tramp-temp-file v) | ||
| 258 | tmpinput (tramp-make-tramp-file-name v input 'nohop)) | ||
| 259 | (copy-file infile tmpinput t))) | ||
| 260 | (when input (setq command (format "%s <%s" command input))) | ||
| 261 | |||
| 247 | (unwind-protect | 262 | (unwind-protect |
| 248 | (apply | 263 | (apply |
| 249 | #'tramp-call-process | 264 | #'tramp-call-process |
| 250 | v (tramp-get-method-parameter v 'tramp-login-program) | 265 | v (tramp-get-method-parameter v 'tramp-login-program) |
| 251 | infile destination display | 266 | nil destination display |
| 252 | (tramp-expand-args | 267 | (tramp-expand-args |
| 253 | v 'tramp-login-args | 268 | v 'tramp-login-args |
| 254 | ?h (or (tramp-file-name-host v) "") | 269 | ?h (or (tramp-file-name-host v) "") |
| @@ -256,7 +271,11 @@ arguments to pass to the OPERATION." | |||
| 256 | ?p (or (tramp-file-name-port v) "") | 271 | ?p (or (tramp-file-name-port v) "") |
| 257 | ?l command)) | 272 | ?l command)) |
| 258 | 273 | ||
| 259 | (unless process-file-side-effects | 274 | ;; Cleanup. We remove all file cache values for the |
| 275 | ;; connection, because the remote process could have changed | ||
| 276 | ;; them. | ||
| 277 | (when tmpinput (delete-file tmpinput)) | ||
| 278 | (when process-file-side-effects | ||
| 260 | (tramp-flush-directory-properties v "")))))) | 279 | (tramp-flush-directory-properties v "")))))) |
| 261 | 280 | ||
| 262 | (defun tramp-sshfs-handle-rename-file | 281 | (defun tramp-sshfs-handle-rename-file |
| @@ -285,6 +304,15 @@ arguments to pass to the OPERATION." | |||
| 285 | (tramp-compat-set-file-modes | 304 | (tramp-compat-set-file-modes |
| 286 | (tramp-fuse-local-file-name filename) mode flag)))) | 305 | (tramp-fuse-local-file-name filename) mode flag)))) |
| 287 | 306 | ||
| 307 | (defun tramp-sshfs-handle-set-file-times (filename &optional timestamp flag) | ||
| 308 | "Like `set-file-times' for Tramp files." | ||
| 309 | (or (file-exists-p filename) (write-region "" nil filename nil 0)) | ||
| 310 | (with-parsed-tramp-file-name filename nil | ||
| 311 | (unless (and (eq flag 'nofollow) (file-symlink-p filename)) | ||
| 312 | (tramp-flush-file-properties v localname) | ||
| 313 | (tramp-compat-set-file-times | ||
| 314 | (tramp-fuse-local-file-name filename) timestamp flag)))) | ||
| 315 | |||
| 288 | (defun tramp-sshfs-handle-write-region | 316 | (defun tramp-sshfs-handle-write-region |
| 289 | (start end filename &optional append visit lockname mustbenew) | 317 | (start end filename &optional append visit lockname mustbenew) |
| 290 | "Like `write-region' for Tramp files." | 318 | "Like `write-region' for Tramp files." |
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index ea0ff3c760e..a07d749916e 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el | |||
| @@ -4504,7 +4504,19 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." | |||
| 4504 | (should | 4504 | (should |
| 4505 | (string-equal (format "%s\n%s\n" fnnd fnnd) (buffer-string))) | 4505 | (string-equal (format "%s\n%s\n" fnnd fnnd) (buffer-string))) |
| 4506 | ;; A non-nil DISPLAY must not raise the buffer. | 4506 | ;; A non-nil DISPLAY must not raise the buffer. |
| 4507 | (should-not (get-buffer-window (current-buffer) t)))) | 4507 | (should-not (get-buffer-window (current-buffer) t)) |
| 4508 | (delete-file tmp-name)) | ||
| 4509 | |||
| 4510 | ;; Check remote and local INFILE. | ||
| 4511 | (dolist (local '(nil t)) | ||
| 4512 | (with-temp-buffer | ||
| 4513 | (setq tmp-name (tramp--test-make-temp-name local quoted)) | ||
| 4514 | (write-region "foo" nil tmp-name) | ||
| 4515 | (should (file-exists-p tmp-name)) | ||
| 4516 | (should (zerop (process-file "cat" tmp-name t))) | ||
| 4517 | (should (string-equal "foo" (buffer-string))) | ||
| 4518 | (should-not (get-buffer-window (current-buffer) t))) | ||
| 4519 | (delete-file tmp-name))) | ||
| 4508 | 4520 | ||
| 4509 | ;; Cleanup. | 4521 | ;; Cleanup. |
| 4510 | (ignore-errors (delete-file tmp-name)))))) | 4522 | (ignore-errors (delete-file tmp-name)))))) |