From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Michael Albinus via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#69085: 29.2; Tramp: Extend tramp-make-copy-program-file-name via tramp-methods Date: Sat, 17 Feb 2024 18:57:51 +0100 Message-ID: <87bk8fug68.fsf@gmx.de> References: <327CF2FD-F00D-402B-B273-12066DDEB0E5@toadstyle.org> <875xytjsfw.fsf@gmx.de> <76B2D222-939F-4096-AFA5-2B0AA92A9A03@toadstyle.org> <8734twimm3.fsf@gmx.de> <87r0hfh6p1.fsf@gmx.de> <70162BD1-DC02-4838-9197-37249010B192@toadstyle.org> <87eddctq6a.fsf@gmx.de> <35B8D855-8524-4B91-B102-5DD9DF81B2EE@toadstyle.org> Reply-To: Michael Albinus Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36304"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 69085@debbugs.gnu.org To: Sean Devlin Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Feb 17 18:59:07 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rbOxu-0009Eo-M8 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 17 Feb 2024 18:59:06 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rbOxY-0000xN-5S; Sat, 17 Feb 2024 12:58:44 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rbOxW-0000xD-Lb for bug-gnu-emacs@gnu.org; Sat, 17 Feb 2024 12:58:42 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rbOxW-0006Sh-Dh for bug-gnu-emacs@gnu.org; Sat, 17 Feb 2024 12:58:42 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rbOxq-0007Is-3Z for bug-gnu-emacs@gnu.org; Sat, 17 Feb 2024 12:59:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Michael Albinus Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 17 Feb 2024 17:59:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 69085 X-GNU-PR-Package: emacs Original-Received: via spool by 69085-submit@debbugs.gnu.org id=B69085.170819270228026 (code B ref 69085); Sat, 17 Feb 2024 17:59:02 +0000 Original-Received: (at 69085) by debbugs.gnu.org; 17 Feb 2024 17:58:22 +0000 Original-Received: from localhost ([127.0.0.1]:33819 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rbOxB-0007Hy-LH for submit@debbugs.gnu.org; Sat, 17 Feb 2024 12:58:22 -0500 Original-Received: from mout.gmx.net ([212.227.15.18]:48013) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rbOx9-0007Hi-9r for 69085@debbugs.gnu.org; Sat, 17 Feb 2024 12:58:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1708192672; x=1708797472; i=michael.albinus@gmx.de; bh=LiFqWCOwc15trYoELzHzR2QFyYxQrQywsNjL8Nw8kNM=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References: Date; b=K37NhdU30d8JXxsaERPZdLho+zbMBmn971uUgn84+mhzvaInUFXdhiTEmCEL4jik 7kAUs99Pnt7Mko237RliO19y6mH8VE+OMQoivJRD5TzEvRNPL7XEV3hEMmGMoeO0K mgocBtHfWZrQPFTHKLIh6qDSavR3ZTEYNzGtvqwzQtRRzAL4r2xOltP9jSzqu0rsA +YhQr/EWbxvYaPAmP8r75xcpc3/A6kHG5GvUe7geQ0vD8sxDgGtetcOfgJO1U0BBB S4FO25Q/2IK4XCfDQl6FXkuDmYl40F565qBrrzlXyqev8TPyuWHvS82iPrYOzLbVW vFnXqH9o+gM8MBnDLw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Original-Received: from gandalf.gmx.de ([185.89.39.16]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MiacH-1qzZh90uqV-00fhOP; Sat, 17 Feb 2024 18:57:52 +0100 In-Reply-To: <35B8D855-8524-4B91-B102-5DD9DF81B2EE@toadstyle.org> (Sean Devlin's message of "Fri, 16 Feb 2024 12:51:17 -0500") X-Provags-ID: V03:K1:/KAVvRM1pz/JVwjMkHEdV8+73sVPYm398k2ptBh25CtREkIWhV4 VDcUBa17fj0fMlGHLMTYk/FPCI0D4YyoDpinx62uz+dgMMWZo1q8liOJQpcXixK5CgJMebi dZa97bX0IAj8Pem88xkGj3nwXVo1Gi57DAMR4AZ54Z7+tLSuxRfeIZgsePTPhRvdHOhYnL6 pDOQCBmLxXuPEy6wnmyzA== UI-OutboundReport: notjunk:1;M01:P0:3LO0/xnysKs=;DTJm3nlJJUZKofs9cn/F8QlNeol ljHQvF3zCuWlyRgoiongM+km64+QAQjOADkTrskx2gV3vTK1pRMXZdg9OHgzJMQvD7FyEhedO EmKWMJFA6hinP33oPpilp2R1xNssH9ExTuYIW9yv/RBH0hYRW6iCFXjkezpoXNKl8LkSqSUIX 49ZKeSXnMvOhNglnhaGQregcTT3OV0vz7gmGAs7lwnD7ZDp8KFfbTo5P/bjDby5DWF71yRXrF NMFxppyN76o88duQn9zWA2199IkyokqqavWXpJtmjB5B1o3u/NAr/Pv+C/nIJ9lx3hQv+Fj+t Qoh9KOA71nDy99BdfV/Ap2vBDlXCVwub7ipgFxe9F8cBzpJNSuNJxZrpo/2hl87fWF6p74oYZ kWHGT2+DAMnrATjjX/MC6Mz0tghJr66y25V7fOYSutPfdsRp2H+MDq/y+RZbs5aB0R1qMiNl8 8ThbLAcJt4z/JhLQCmPM62iFayp3a0L0nIBbEmYUk61Cy7WifXD1PsU5NdGLIxDubA3W4RbXP 5pX6HJcFoYysWbv4uuaubmgxR5mfdu3996cpP7aq2hHHpcUC9+Tjxfhm0HbdAAhhPqjRno+nc tJmUFGxMvWLAwz0qb3Gb8fNePfn3g4RXZdr4uhDxzf/zdWQiXWuGr4hO/BeJm5/CPPVI4PFSK rBn3jBB2jIwRXmjrRk56HafCgSTCYKIV/oPgHgbLufEBJbjqYNYUrSctMNAEkQU+oyzzcr1tX +9TTz4YqfdR+NnNwhwZnBe6oj8Cm8vS3pUyCtZKf6NcC00JvHRvi1IyKJ0rGtuOS08ZX96bw X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:280137 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Sean Devlin writes: > Hi Michael, Hi Sean, > The patch does work as described, but it doesn=E2=80=99t integrate well w= ith typical > workflows. > > So while this approach does work for Docker containers, it adds some > ergonomic overhead for the user making it inconvenient to use. I see your point. Appended is a new patch, which addresses your inconvenience. Could you pls apply it on top of Tramp 2.7 instead of the other patch? The method "dockercp" allows now user names, which are ignored when calling "docker cp ...". > Thanks, > > Sean Best regards, Michael. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment Content-Transfer-Encoding: quoted-printable diff --git a/lisp/tramp-container.el b/lisp/tramp-container.el index 1f578949..ff2e11b5 100644 =2D-- a/lisp/tramp-container.el +++ b/lisp/tramp-container.el @@ -31,15 +31,20 @@ ;; Open a file on a running Docker container: ;; ;; C-x C-f /docker:USER@CONTAINER:/path/to/file +;; C-x C-f /dockercp:USER@CONTAINER:/path/to/file ;; ;; or Podman: ;; ;; C-x C-f /podman:USER@CONTAINER:/path/to/file +;; C-x C-f /podmancp:USER@CONTAINER:/path/to/file ;; ;; Where: ;; USER is the user on the container to connect as (optional= ). ;; CONTAINER is the container to connect to. ;; +;; "docker" and "podman" are inline methods, "dockercp" and "podmancp" +;; are out-of-band methods. +;; ;; ;; ;; Open file in a Kubernetes container: @@ -141,10 +146,20 @@ If it is nil, the default context will be used." (defconst tramp-docker-method "docker" "Tramp method name to use to connect to Docker containers.") +;;;###tramp-autoload +(defconst tramp-dockercp-method "dockercp" + "Tramp method name to use to connect to Docker containers. +This is for out-of-band connections.") + ;;;###tramp-autoload (defconst tramp-podman-method "podman" "Tramp method name to use to connect to Podman containers.") +;;;###tramp-autoload +(defconst tramp-podmancp-method "podmancp" + "Tramp method name to use to connect to Podman containers. +This is for out-of-band connections.") + ;;;###tramp-autoload (defconst tramp-kubernetes-method "kubernetes" "Tramp method name to use to connect to Kubernetes containers.") @@ -183,7 +198,8 @@ BODY is the backend specific code." (defun tramp-container--completion-function (method) "List running containers available for connection. METHOD is the Tramp method to be used for \"ps\", either -`tramp-docker-method' or `tramp-podman-method'. +`tramp-docker-method', `tramp-dockercp-method', `tramp-podman-method', +or `tramp-podmancp-method'. This function is used by `tramp-set-completion-function', please see its function help for a description of the format." @@ -375,6 +391,22 @@ see its function help for a description of the format= ." (tramp-remote-shell-login ("-l")) (tramp-remote-shell-args ("-i" "-c")))) + (add-to-list 'tramp-methods + `(,tramp-dockercp-method + (tramp-login-program ,tramp-docker-program) + (tramp-login-args (("exec") + ("-it") + ("-u" "%u") + ("%h") + ("%l"))) + (tramp-direct-async (,tramp-default-remote-shell "-c")) + (tramp-remote-shell ,tramp-default-remote-shell) + (tramp-remote-shell-login ("-l")) + (tramp-remote-shell-args ("-i" "-c")) + (tramp-copy-program ,tramp-docker-program) + (tramp-copy-args (("cp"))) + (tramp-copy-file-name (("%h" ":") ("%f"))))) + (add-to-list 'tramp-methods `(,tramp-podman-method (tramp-login-program ,tramp-podman-program) @@ -388,6 +420,22 @@ see its function help for a description of the format= ." (tramp-remote-shell-login ("-l")) (tramp-remote-shell-args ("-i" "-c")))) + (add-to-list 'tramp-methods + `(,tramp-podmancp-method + (tramp-login-program ,tramp-podman-program) + (tramp-login-args (("exec") + ("-it") + ("-u" "%u") + ("%h") + ("%l"))) + (tramp-direct-async (,tramp-default-remote-shell "-c")) + (tramp-remote-shell ,tramp-default-remote-shell) + (tramp-remote-shell-login ("-l")) + (tramp-remote-shell-args ("-i" "-c")) + (tramp-copy-program ,tramp-podman-program) + (tramp-copy-args (("cp"))) + (tramp-copy-file-name (("%h" ":") ("%f"))))) + (add-to-list 'tramp-methods `(,tramp-kubernetes-method (tramp-login-program ,tramp-kubernetes-program) @@ -431,10 +479,18 @@ see its function help for a description of the forma= t." tramp-docker-method `((tramp-container--completion-function ,tramp-docker-method))) + (tramp-set-completion-function + tramp-dockercp-method + `((tramp-container--completion-function ,tramp-dockercp-method))) + (tramp-set-completion-function tramp-podman-method `((tramp-container--completion-function ,tramp-podman-method))) + (tramp-set-completion-function + tramp-podmancp-method + `((tramp-container--completion-function ,tramp-podmancp-method))) + (tramp-set-completion-function tramp-kubernetes-method `((tramp-kubernetes--completion-function ,tramp-kubernetes-method))) diff --git a/lisp/tramp-sh.el b/lisp/tramp-sh.el index 3557b3a1..b3ab5609 100644 =2D-- a/lisp/tramp-sh.el +++ b/lisp/tramp-sh.el @@ -282,6 +282,7 @@ The string is used in `tramp-methods'.") (tramp-copy-program "nc") ;; We use "-v" for better error tracking. (tramp-copy-args (("-w" "1") ("-v") ("%h") ("%= r"))) + (tramp-copy-file-name (("%f"))) (tramp-remote-copy-program "nc") ;; We use "-p" as required for newer busyboxes. For olde= r ;; busybox/nc versions, the value must be (("-l") ("%r"))= . This @@ -2399,10 +2400,10 @@ The method used must be an out-of-band method." #'file-name-as-directory #'identity) (if v1 - (tramp-make-copy-program-file-name v1) + (tramp-make-copy-file-name v1) (file-name-unquote filename))) target (if v2 - (tramp-make-copy-program-file-name v2) + (tramp-make-copy-file-name v2) (file-name-unquote newname))) ;; Check for listener port. @@ -5559,13 +5560,17 @@ raises an error." string "")) -(defun tramp-make-copy-program-file-name (vec) +(defun tramp-make-copy-file-name (vec) "Create a file name suitable for `scp', `pscp', or `nc' and workalikes.= " (let ((method (tramp-file-name-method vec)) (user (tramp-file-name-user vec)) (host (tramp-file-name-host vec)) (localname (directory-file-name (tramp-file-name-unquote-localname vec)))) + ;; Set the default value of connection property "copy-file-name". + (unless (tramp-get-method-parameter vec 'tramp-copy-file-name) + (tramp-set-connection-property + vec "copy-file-name" '(("%u" "@") ("%h" ":") ("%f")))) (when (string-match-p tramp-ipv6-regexp host) (setq host (format "[%s]" host))) ;; This does not work for MS Windows scp, if there are characters @@ -5573,11 +5578,10 @@ raises an error." ;; checking in scp, we use it when available. (unless (string-match-p (rx "ftp" eos) method) (setq localname (tramp-unquote-shell-quote-argument localname))) - (cond - ((tramp-get-method-parameter vec 'tramp-remote-copy-program) - localname) - ((tramp-string-empty-or-nil-p user) (format "%s:%s" host localname)) - (t (format "%s@%s:%s" user host localname))))) + (string-join + (apply #'tramp-expand-args vec 'tramp-copy-file-name + (list ?h (or host "") ?u (or user "") ?f localname)) + ""))) (defun tramp-method-out-of-band-p (vec size) "Return t if this is an out-of-band method, nil otherwise." diff --git a/lisp/tramp.el b/lisp/tramp.el index 2efee234..0e64b779 100644 =2D-- a/lisp/tramp.el +++ b/lisp/tramp.el @@ -301,6 +301,14 @@ pair of the form (KEY VALUE). The following KEYs are= defined: This specifies the list of parameters to pass to the above mentioned program, the hints for `tramp-login-args' also apply here. + * `tramp-copy-file-name' + The remote source or destination file name for out-of-band methods. + You can use the \"%u\" and \"%h\" like in `tramp-login-args'. + Additionally, \"%f\" denotes the local file name part. It will be + expanded to a string without spaces between the elements of the list. + + The default value is \\=3D'((\"%u\" \"@\") (\"%h\" \":\") (\"%f\")) + * `tramp-copy-env' A list of environment variables and their values, which will be set when calling `tramp-copy-program'. --=-=-=--