From 8bff4e006e8451191c14a3c5ec769790535ca36d Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Wed, 13 Nov 2024 16:23:27 +0100 Subject: [PATCH] Tramp: Rework handling of temporary connection properties * doc/misc/tramp.texi (Ad-hoc multi-hops): Precise use of parallel multi-hops. * lisp/net/tramp-cache.el: * lisp/net/tramp.el: * lisp/net/tramp-adb.el: * lisp/net/tramp-androidsu.el: * lisp/net/tramp-cmds.el: * lisp/net/tramp-crypt.el: * lisp/net/tramp-gvfs.el: * lisp/net/tramp-sh.el: * lisp/net/tramp-smb.el: Rename connection properties "process-name", "process-buffer" and "first-password-request" to " process-name", " process-buffer" and " first-password-request, repectively". * lisp/net/tramp-cache.el (tramp-dump-connection-properties): Don't dump properties starting with a space. (cherry picked from commit 22900b5990888cb231d65755562879108c626088) --- doc/misc/tramp.texi | 3 +++ lisp/net/tramp-adb.el | 10 +++++----- lisp/net/tramp-androidsu.el | 2 +- lisp/net/tramp-cache.el | 11 +++++------ lisp/net/tramp-cmds.el | 2 +- lisp/net/tramp-crypt.el | 4 ++-- lisp/net/tramp-gvfs.el | 4 ++-- lisp/net/tramp-sh.el | 24 ++++++++++++------------ lisp/net/tramp-smb.el | 34 +++++++++++++++++----------------- lisp/net/tramp.el | 26 +++++++++++++------------- 10 files changed, 61 insertions(+), 59 deletions(-) diff --git a/doc/misc/tramp.texi b/doc/misc/tramp.texi index 8b8cd1ae553..dac0701bd5b 100644 --- a/doc/misc/tramp.texi +++ b/doc/misc/tramp.texi @@ -3941,6 +3941,9 @@ parallel. In the following, on both remote hosts @samp{host1} and @trampfn{ssh@value{postfixhop}user2@@host2|docker,name,} @end example +If you use the shortened name @samp{@trampfn{docker,name,}}, the last +used proxy definition is expanded for. + @node Home directories @section Expanding @file{~} to home directory diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el index ad82aad6a32..5a7176c3ec8 100644 --- a/lisp/net/tramp-adb.el +++ b/lisp/net/tramp-adb.el @@ -811,10 +811,10 @@ will be used." v 'file-error "Cannot apply multibyte command `%s'" command)) (with-tramp-saved-connection-properties - v '("process-name" "process-buffer") + v '(" process-name" " process-buffer") ;; Set the new process properties. - (tramp-set-connection-property v "process-name" name) - (tramp-set-connection-property v "process-buffer" buffer) + (tramp-set-connection-property v " process-name" name) + (tramp-set-connection-property v " process-buffer" buffer) (with-current-buffer (tramp-get-connection-buffer v) (unwind-protect ;; We catch this event. Otherwise, `make-process' @@ -857,8 +857,8 @@ will be used." ;; We must flush them here already; ;; otherwise `rename-file', `delete-file' ;; or `insert-file-contents' will fail. - (tramp-flush-connection-property v "process-name") - (tramp-flush-connection-property v "process-buffer") + (tramp-flush-connection-property v " process-name") + (tramp-flush-connection-property v " process-buffer") ;; Copy tmpstderr file. (when (and (stringp stderr) (not (tramp-tramp-file-p stderr))) diff --git a/lisp/net/tramp-androidsu.el b/lisp/net/tramp-androidsu.el index 473cecf7a1b..9e99838f751 100644 --- a/lisp/net/tramp-androidsu.el +++ b/lisp/net/tramp-androidsu.el @@ -111,7 +111,7 @@ multibyte mode and waits for the shell prompt to appear." (with-tramp-debug-message vec "Opening connection" (let ((p (tramp-get-connection-process vec)) - (process-name (tramp-get-connection-property vec "process-name")) + (process-name (tramp-get-connection-property vec " process-name")) (process-environment (copy-sequence process-environment))) ;; Open a new connection. (condition-case err diff --git a/lisp/net/tramp-cache.el b/lisp/net/tramp-cache.el index 16893ea8c82..85fe295358e 100644 --- a/lisp/net/tramp-cache.el +++ b/lisp/net/tramp-cache.el @@ -68,7 +68,7 @@ ;; Some properties are handled special: ;; -;; - "process-name", "process-buffer" and "first-password-request" are +;; - Properties which start with a space, like " process-name", are ;; not saved in the file `tramp-persistency-file-name', although ;; being connection properties related to a `tramp-file-name' ;; structure. @@ -554,7 +554,7 @@ PROPERTIES is a list of file properties (strings)." (lambda (key) (and (tramp-file-name-p key) (null (tramp-file-name-localname key)) - (tramp-connection-property-p key "process-buffer") + (tramp-connection-property-p key " process-buffer") key)) (hash-table-keys tramp-cache-data)))) @@ -586,10 +586,9 @@ PROPERTIES is a list of file properties (strings)." (not (tramp-file-name-localname key)) (not (gethash "login-as" value)) (not (gethash "started" value))) - (progn - (remhash "process-name" value) - (remhash "process-buffer" value) - (remhash "first-password-request" value)) + (dolist (k (hash-table-keys value)) + (when (string-prefix-p " " k) + (remhash k value))) (remhash key cache))) cache) ;; Dump it. diff --git a/lisp/net/tramp-cmds.el b/lisp/net/tramp-cmds.el index d37bb612255..733c96fcfaa 100644 --- a/lisp/net/tramp-cmds.el +++ b/lisp/net/tramp-cmds.el @@ -171,7 +171,7 @@ interactively, a Tramp connection has to be selected." (get-buffer (tramp-debug-buffer-name vec))) (unless keep-debug (get-buffer (tramp-trace-buffer-name vec))) - (tramp-get-connection-property vec "process-buffer"))) + (tramp-get-connection-property vec " process-buffer"))) (when (bufferp buf) (kill-buffer buf))) ;; Flush file cache. diff --git a/lisp/net/tramp-crypt.el b/lisp/net/tramp-crypt.el index 8954d06b9b5..8f151e0dc03 100644 --- a/lisp/net/tramp-crypt.el +++ b/lisp/net/tramp-crypt.el @@ -352,7 +352,7 @@ connection if a previous connection has died for some reason." (tramp-compat-make-temp-file " .nocrypt" 'dir-flag)))) ;; Enable `auth-source', unless "emacs -Q" has been called. (tramp-set-connection-property - vec "first-password-request" tramp-cache-read-persistent-data) + vec " first-password-request" tramp-cache-read-persistent-data) (with-temp-buffer (insert (tramp-read-passwd @@ -408,7 +408,7 @@ ARGS are the arguments. It returns t if ran successful, and nil otherwise." (args (delq nil args))) ;; Enable `auth-source', unless "emacs -Q" has been called. (tramp-set-connection-property - vec "first-password-request" tramp-cache-read-persistent-data) + vec " first-password-request" tramp-cache-read-persistent-data) (insert (tramp-read-passwd (tramp-get-connection-process vec) diff --git a/lisp/net/tramp-gvfs.el b/lisp/net/tramp-gvfs.el index 7b85ecc1192..9895777919f 100644 --- a/lisp/net/tramp-gvfs.el +++ b/lisp/net/tramp-gvfs.el @@ -1799,7 +1799,7 @@ a downcased host name only." (setq domain (read-string "Domain name: "))) (tramp-message l 6 "%S %S %S %d" message user domain flags) - (unless (tramp-get-connection-property l "first-password-request") + (unless (tramp-get-connection-property l " first-password-request") (tramp-clear-passwd l)) (setq password (tramp-read-passwd @@ -2249,7 +2249,7 @@ connection if a previous connection has died for some reason." ;; Enable `auth-source'. (tramp-set-connection-property - vec "first-password-request" tramp-cache-read-persistent-data) + vec " first-password-request" tramp-cache-read-persistent-data) ;; There will be a callback of "askPassword" when a password is needed. (dbus-register-method diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index 8703087f66d..eab1dd41d76 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el @@ -2567,16 +2567,16 @@ The method used must be an out-of-band method." (with-temp-buffer (unwind-protect (with-tramp-saved-connection-properties - v '("process-name" "process-buffer") + v '(" process-name" " process-buffer") ;; The default directory must be remote. (let ((default-directory (file-name-directory (if v1 filename newname))) (process-environment (copy-sequence process-environment))) ;; Set the transfer process properties. (tramp-set-connection-property - v "process-name" (buffer-name (current-buffer))) + v " process-name" (buffer-name (current-buffer))) (tramp-set-connection-property - v "process-buffer" (current-buffer)) + v " process-buffer" (current-buffer)) (when copy-env (tramp-message v 6 "%s=\"%s\"" @@ -3084,10 +3084,10 @@ will be used." :file-handler t)) (with-tramp-saved-connection-properties - v '("process-name" "process-buffer") + v '(" process-name" " process-buffer") ;; Set the new process properties. - (tramp-set-connection-property v "process-name" name) - (tramp-set-connection-property v "process-buffer" buffer) + (tramp-set-connection-property v " process-name" name) + (tramp-set-connection-property v " process-buffer" buffer) (with-current-buffer (tramp-get-connection-buffer v) (unwind-protect ;; We catch this event. Otherwise, `make-process' @@ -3169,8 +3169,8 @@ will be used." (set-marker (process-mark p) (point))) ;; We must flush them here already; otherwise ;; `delete-file' will fail. - (tramp-flush-connection-property v "process-name") - (tramp-flush-connection-property v "process-buffer") + (tramp-flush-connection-property v " process-name") + (tramp-flush-connection-property v " process-buffer") ;; Kill stderr process and delete named pipe. (when (bufferp stderr) (add-function @@ -4326,7 +4326,7 @@ file exists and nonzero exit status otherwise." (defun tramp-find-shell (vec) "Open a shell on the remote host which groks tilde expansion." ;; If we are in `make-process', we don't need another shell. - (unless (tramp-get-connection-property vec "process-name") + (unless (tramp-get-connection-property vec " process-name") (with-current-buffer (tramp-get-buffer vec) (let ((default-shell (tramp-get-method-parameter vec 'tramp-remote-shell)) shell) @@ -4431,7 +4431,7 @@ process to set up. VEC specifies the connection." (let* ((old-uname (tramp-get-connection-property vec "uname")) (uname ;; If we are in `make-process', we don't need to recompute. - (if (and old-uname (tramp-get-connection-property vec "process-name")) + (if (and old-uname (tramp-get-connection-property vec " process-name")) old-uname (tramp-set-connection-property vec "uname" @@ -4445,7 +4445,7 @@ process to set up. VEC specifies the connection." (and config-check-function ;; If we are in `make-process', we don't need to recompute. (if (and old-config-check - (tramp-get-connection-property vec "process-name")) + (tramp-get-connection-property vec " process-name")) old-config-check (tramp-set-connection-property vec "config-check-data" @@ -5113,7 +5113,7 @@ connection if a previous connection has died for some reason." (with-tramp-debug-message vec "Opening connection" (let ((p (tramp-get-connection-process vec)) - (process-name (tramp-get-connection-property vec "process-name")) + (process-name (tramp-get-connection-property vec " process-name")) (process-environment (copy-sequence process-environment)) (pos (with-current-buffer (tramp-get-connection-buffer vec) (point)))) diff --git a/lisp/net/tramp-smb.el b/lisp/net/tramp-smb.el index 2699dc13043..c138600be67 100644 --- a/lisp/net/tramp-smb.el +++ b/lisp/net/tramp-smb.el @@ -526,13 +526,13 @@ arguments to pass to the OPERATION." (unwind-protect (with-tramp-saved-connection-properties - v '("process-name" "process-buffer") + v '(" process-name" " process-buffer") (with-temp-buffer ;; Set the transfer process properties. (tramp-set-connection-property - v "process-name" (buffer-name (current-buffer))) + v " process-name" (buffer-name (current-buffer))) (tramp-set-connection-property - v "process-buffer" (current-buffer)) + v " process-buffer" (current-buffer)) (when t1 ;; The smbclient tar command creates @@ -799,13 +799,13 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored." (concat "2>" (tramp-get-remote-null-device v))))) (with-tramp-saved-connection-properties - v '("process-name" "process-buffer") + v '(" process-name" " process-buffer") (with-temp-buffer ;; Set the transfer process properties. (tramp-set-connection-property - v "process-name" (buffer-name (current-buffer))) + v " process-name" (buffer-name (current-buffer))) (tramp-set-connection-property - v "process-buffer" (current-buffer)) + v " process-buffer" (current-buffer)) ;; Use an asynchronous process. By this, password ;; can be handled. @@ -1247,11 +1247,11 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored." ;; Call it. (condition-case nil (with-tramp-saved-connection-properties - v '("process-name" "process-buffer") + v '(" process-name" " process-buffer") ;; Set the new process properties. - (tramp-set-connection-property v "process-name" name1) + (tramp-set-connection-property v " process-name" name1) (tramp-set-connection-property - v "process-buffer" + v " process-buffer" (or outbuf (generate-new-buffer tramp-temp-buffer-name))) (with-current-buffer (tramp-get-connection-buffer v) ;; Preserve buffer contents. @@ -1287,9 +1287,9 @@ 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)) - ;; FIXME: Does connection-property "process-buffer" still exist? + ;; FIXME: Does connection-property " process-buffer" still exist? (unless outbuf - (kill-buffer (tramp-get-connection-property v "process-buffer"))) + (kill-buffer (tramp-get-connection-property v " process-buffer"))) (when process-file-side-effects (tramp-flush-directory-properties v "/")) @@ -1388,13 +1388,13 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored." "||" "echo" "tramp_exit_status" "1"))) (with-tramp-saved-connection-properties - v '("process-name" "process-buffer") + v '(" process-name" " process-buffer") (with-temp-buffer ;; Set the transfer process properties. (tramp-set-connection-property - v "process-name" (buffer-name (current-buffer))) + v " process-name" (buffer-name (current-buffer))) (tramp-set-connection-property - v "process-buffer" (current-buffer)) + v " process-buffer" (current-buffer)) ;; Use an asynchronous process. By this, password ;; can be handled. @@ -1450,7 +1450,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored." p) (unwind-protect (with-tramp-saved-connection-properties - v '("process-name" "process-buffer") + v '(" process-name" " process-buffer") (save-excursion (save-restriction (while (get-process name1) @@ -1458,8 +1458,8 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored." (setq i (1+ i) name1 (format "%s<%d>" name i))) ;; Set the new process properties. - (tramp-set-connection-property v "process-name" name1) - (tramp-set-connection-property v "process-buffer" buffer) + (tramp-set-connection-property v " process-name" name1) + (tramp-set-connection-property v " process-buffer" buffer) ;; Activate narrowing in order to save BUFFER contents. (with-current-buffer (tramp-get-connection-buffer v) (let ((buffer-undo-list t)) diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index a4e8fe42048..6e1b9e66478 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -1959,11 +1959,11 @@ Unless DONT-CREATE, the buffer is created when it doesn't exist yet." (or (get-buffer (tramp-buffer-name vec)) (unless dont-create (with-current-buffer (get-buffer-create (tramp-buffer-name vec)) - ;; We use the existence of connection property "process-buffer" + ;; We use the existence of connection property " process-buffer" ;; as indication, whether a connection is active. (tramp-set-connection-property - vec "process-buffer" - (tramp-get-connection-property vec "process-buffer")) + vec " process-buffer" + (tramp-get-connection-property vec " process-buffer")) (setq buffer-undo-list t default-directory (tramp-make-tramp-file-name vec 'noloc)) @@ -1975,14 +1975,14 @@ Unless DONT-CREATE, the buffer is created when it doesn't exist yet." Unless DONT-CREATE, the buffer is created when it doesn't exist yet. In case a second asynchronous communication has been started, it is different from `tramp-get-buffer'." - (or (tramp-get-connection-property vec "process-buffer") + (or (tramp-get-connection-property vec " process-buffer") (tramp-get-buffer vec dont-create))) (defun tramp-get-connection-name (vec) "Get the connection name to be used for VEC. In case a second asynchronous communication has been started, it is different from the default one." - (or (tramp-get-connection-property vec "process-name") + (or (tramp-get-connection-property vec " process-name") (tramp-buffer-name vec))) (defun tramp-get-unique-process-name (name) @@ -2481,7 +2481,7 @@ Fall back to normal file name handler if no Tramp file name handler exists." (with-tramp-debug-message v (format "Running `%S'" (cons operation args)) ;; We flush connection properties - ;; "process-name" and "process-buffer", + ;; " process-name" and " process-buffer", ;; because the operations shall be applied ;; in the main connection process. In order ;; to avoid superfluous debug buffers during @@ -2496,12 +2496,12 @@ Fall back to normal file name handler if no Tramp file name handler exists." ;; a short time frame. ;; In both cases, we try the default handler then. (with-tramp-saved-connection-properties - v '("process-name" "process-buffer") + v '(" process-name" " process-buffer") (let ((tramp-verbose (if minibuffer-completing-file-name 0 tramp-verbose))) - (tramp-flush-connection-property v "process-name") - (tramp-flush-connection-property v "process-buffer")) + (tramp-flush-connection-property v " process-name") + (tramp-flush-connection-property v " process-buffer")) (setq result (catch 'non-essential (catch 'suppress @@ -5689,7 +5689,7 @@ of." ;; Sometimes, the process returns a new password request ;; immediately after rejecting the previous (wrong) one. (unless (or tramp-password-prompt-not-unique - (tramp-get-connection-property vec "first-password-request")) + (tramp-get-connection-property vec " first-password-request")) (tramp-clear-passwd vec)) (goto-char (point-min)) (tramp-check-for-regexp proc tramp-process-action-regexp) @@ -5896,7 +5896,7 @@ performed successfully. Any other value means an error." (tramp-set-connection-property (tramp-get-connection-property proc "password-vector" (process-get proc 'tramp-vector)) - "first-password-request" tramp-cache-read-persistent-data) + " first-password-request" tramp-cache-read-persistent-data) (save-restriction (with-tramp-progress-reporter proc 3 "Waiting for prompts from remote shell" @@ -6898,7 +6898,7 @@ Consults the auth-source package." ;; See if auth-sources contains something useful. (ignore-errors (and auth-sources - (tramp-get-connection-property vec "first-password-request") + (tramp-get-connection-property vec " first-password-request") ;; Try with Tramp's current method. If there is no ;; user name, `:create' triggers to ask for. We ;; suppress it. @@ -6920,7 +6920,7 @@ Consults the auth-source package." (lambda () (password-cache-add key auth-passwd))) auth-passwd)) - (tramp-set-connection-property vec "first-password-request" nil)))) + (tramp-set-connection-property vec " first-password-request" nil)))) (defun tramp-read-passwd-without-cache (proc &optional prompt) "Read a password from user (compat function)." -- 2.39.5