all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Sean Devlin <spd@toadstyle.org>
To: Michael Albinus <michael.albinus@gmx.de>
Cc: 69085@debbugs.gnu.org
Subject: bug#69085: 29.2; Tramp: Extend tramp-make-copy-program-file-name via tramp-methods
Date: Wed, 14 Feb 2024 19:57:13 -0500	[thread overview]
Message-ID: <70162BD1-DC02-4838-9197-37249010B192@toadstyle.org> (raw)
In-Reply-To: <87r0hfh6p1.fsf@gmx.de>

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

Hi Michael,

> On Feb 14, 2024, at 1:59 AM, Michael Albinus <michael.albinus@gmx.de> wrote:
> 
> Sean Devlin <spd@toadstyle.org> writes:
> 
>> Hi Michael,
> 
> Hi Sean,
> 
>>> - And if HOST is a kind of container, would it be possible for you to
>>> use the "docker" or "podman" method of Tramp directly?
>> 
>> I’ve looked a little bit at the code supporting these methods in tramp-container.el.
>> They seem similar, but not exactly the same. Also, they do not support OOB
>> copying, at least in the version of Tramp I’m reading (i.e. the version packaged with
>> Emacs 29.2).
> 
> Could you pls elaborate verbosely, what is missing in your use case?
> Perhaps we could extend tramp-container.el that it is applicable for you
> as well.

Sure, let’s focus on tramp-container.el. I think this will allow us to be
concrete, which will make things simpler to discuss.

Suppose we want to add OOB copying to the Docker method. Docker
has a copy command with usage like this:

Usage:  docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-
	docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH

We could try to add support to the Docker method for OOB copying by
starting Emacs -Q and evaluating these forms:

(require 'tramp-container)
(add-to-list 'tramp-methods
             `(,tramp-docker-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")))
	       ))

Outside of Emacs, start a Docker container running some image (e.g.
ubuntu:latest). An example command is:

$ docker run -it ubuntu:latest bash -l

Leave this running.

Next, create a large (i.e. greater than tramp-copy-size-limit) temporary
file for copying:

$ head -c 20000 /dev/random > /tmp/bigfile

Back in Emacs, evaluate these forms (with “my_container” replaced with
the name of your container):

(copy-file "/tmp/bigfile" "/docker:my_container:/tmp/bigfile")

(copy-file "/tmp/bigfile" "/docker:root@my_container:/tmp/bigfile2”)

The first copy will succeed, but the second will fail. This is because the
connection has an explicit user, so it will try to run a command like:

docker cp /tmp/bigfile root@my_container:/tmp/bigfile2

It will fail because it will interpret “root@my_container” as the container’s
name, and it will say that there is no container by that name.

I think what is needed is some way for the tramp-docker method to specify
the format for remote paths in the OOB copy command, since
tramp-make-copy-program-file-name will include the user if it is specified
in the connection.

One method might be to add a key to tramp-methods that lets you specify
the format similar to tramp-login-args and tramp-copy-args:

(tramp-copy-remote-file-format (("%h" ":" "%f")))

Where “%h” and “%f” are the host and the file’s local name, respectively.

Like tramp-login-args, the format could be a list of lists, and sublists could
be ignored when the required properties are absent. For example, the
format for scp-like copy programs might look like this:

(tramp-copy-remote-file-format
 (("%u" "@")
  ("%h" ":" "%f")))

Where “%u” is the user. So the leading “user@“ could be dropped if the
user is unspecified.

Unlike tramp-login-args and tramp-copy-args, this would need to
concatenate the strings together without spaces.

The function tramp-make-copy-program-file-name could check for this
method parameter and, if present, use it to format the result. For example,
the cond at the end could be changed like so:

(let ((fmt (tramp-get-method-parameter vec 'tramp-copy-remote-file-format)))
  (cond
   ((tramp-get-method-parameter vec 'tramp-remote-copy-program)
    localname)
   (fmt
    ;; Format the file name using fmt.
    )
   ((tramp-string-empty-or-nil-p user) (format "%s:%s" host localname))
   (t (format "%s@%s:%s" user host localname)))

Instead of a list of lists of strings, another method would be to specify a
function that does the work. The function could take the vector as input and
return the formatted file name. The tramp-make-copy-program-file-name
function could call that function (if specified) at the same place in that cond
form. This would be more flexible than the list of lists of strings, but it also
would be more complicated for the implementer and may be overkill.

> 
> (I take the time to invest it with you, because your urgent problem seems
> to be mitigated by your defadvice.)

I appreciate your help—thank you for taking the time!

> 
>> Thanks for your help!
> 
> Best regards, Michael.


[-- Attachment #2: Type: text/html, Size: 7945 bytes --]

  reply	other threads:[~2024-02-15  0: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 [this message]
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
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=70162BD1-DC02-4838-9197-37249010B192@toadstyle.org \
    --to=spd@toadstyle.org \
    --cc=69085@debbugs.gnu.org \
    --cc=michael.albinus@gmx.de \
    /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.