all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Michael Albinus via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Sean Devlin <spd@toadstyle.org>
Cc: 69085@debbugs.gnu.org
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	[thread overview]
Message-ID: <87bk8fug68.fsf@gmx.de> (raw)
In-Reply-To: <35B8D855-8524-4B91-B102-5DD9DF81B2EE@toadstyle.org> (Sean Devlin's message of "Fri, 16 Feb 2024 12:51:17 -0500")

[-- Attachment #1: Type: text/plain, Size: 610 bytes --]

Sean Devlin <spd@toadstyle.org> writes:

> Hi Michael,

Hi Sean,

> The patch does work as described, but it doesn’t integrate well with 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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 8424 bytes --]

diff --git a/lisp/tramp-container.el b/lisp/tramp-container.el
index 1f578949..ff2e11b5 100644
--- 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 format."
   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
--- 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 older
                 ;; 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
--- 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 \\='((\"%u\" \"@\") (\"%h\" \":\") (\"%f\"))
+
   * `tramp-copy-env'
      A list of environment variables and their values, which will
      be set when calling `tramp-copy-program'.

  reply	other threads:[~2024-02-17 17:57 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-12 20:08 bug#69085: 29.2; Tramp: Extend tramp-make-copy-program-file-name via tramp-methods Sean Devlin
     [not found] ` <handler.69085.B.17077686248331.ack@debbugs.gnu.org>
2024-02-12 20:14   ` bug#69085: Acknowledgement (29.2; Tramp: Extend tramp-make-copy-program-file-name via tramp-methods) Sean Devlin
2024-02-12 21:16     ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-12 21:14 ` bug#69085: 29.2; Tramp: Extend tramp-make-copy-program-file-name via tramp-methods Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-12 21:51   ` Sean Devlin
2024-02-13 12:18     ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-13 20:18       ` Sean Devlin
2024-02-14  6:59         ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-15  0:57           ` Sean Devlin
2024-02-16 14:54             ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-16 17:51               ` Sean Devlin
2024-02-17 17:57                 ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-02-19 19:19                   ` Sean Devlin
2024-02-20 12:04                     ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-20 16:15                       ` Sean Devlin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bk8fug68.fsf@gmx.de \
    --to=bug-gnu-emacs@gnu.org \
    --cc=69085@debbugs.gnu.org \
    --cc=michael.albinus@gmx.de \
    --cc=spd@toadstyle.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.