Skip to content

LinuxContainer: Support copying directories#571

Merged
dcantah merged 1 commit intoapple:mainfrom
dcantah:copy-dir-support
Mar 6, 2026
Merged

LinuxContainer: Support copying directories#571
dcantah merged 1 commit intoapple:mainfrom
dcantah:copy-dir-support

Conversation

@dcantah
Copy link
Member

@dcantah dcantah commented Mar 5, 2026

Now that the static linux SDK we use has libarchive linked against it, we can finally live our dream (/s) of supporting copying directories in/out a little easier. This was.. kind of annoying. I think the very simple route of writing archive to guest/host -> streaming over grpc is simplest, but on the guest end we have a couple problems:

  1. The VMs rootfs is read only today always, which is a good thing to me and I don't want to change if we don't have to.
  2. Writing the archive to the containers rootfs temporarily could work, but it's a bit weird, and the user can make the containers rootfs readonly which would screw that plan.
  3. We could write it to /run or /tmp, but they're tmpfs and dealing with the headache of the user possibly tarring an enormous dir is one I don't want to care about.

So, that leaves us with the (truthfully better to me) approach of trying to write the tar data directly to the host and skipping grpc which kinda forces us to have a temp spot. Because of that, I made it such that we pass a port number from host<->guest, and transfer the actual data (either the single file or tarred dir contents) over the vsock port instead. The stream is kinda clunky, but it just serves as a means to exchange metadata and a "we're done" signifier.

Now that the static linux SDK we use has libarchive linked against it,
we can finally live our dream (/s) of supporting copying directories
in/out a little easier. This was.. kind of annoying. I think the
very simple route of writing archive to guest/host -> streaming over
grpc is simplest, but on the guest end we have a couple problems:

1. The VMs rootfs is read only today always, which is a good thing to me
and I don't want to change if we don't have to.
2. Writing the archive to the containers rootfs temporarily could work,
but it's a bit weird, and the user can make the containers rootfs readonly
which would screw that plan.
3. We could write it to /run or /tmp, but they're tmpfs and dealing with the
headache of the user possibly tarring an enormous dir is one I don't want to
care about.

So, that leaves us with the (truthfully better to me) approach of trying to write
the tar data directly to the host and skipping grpc which kinda forces us to
have a temp spot. Because of that, I made it such that we pass a port number from
host<->guest, and transfer the actual data (either the single file or tarred dir
contents) over the vsock port instead. The stream is kinda clunky, but it just serves
as a means to exchange metadata and a "we're done" signifier.
@dcantah dcantah force-pushed the copy-dir-support branch from b65afd9 to a2a62f7 Compare March 5, 2026 21:59
///
/// For COPY_OUT, the `onMetadata` callback is invoked when the guest sends
/// metadata (is_archive, total_size) before data transfer begins.
/// For COPY_IN, `onMetadata` is not called.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it called anyway? Couldn't find different path for COPY_IN.

@dcantah dcantah marked this pull request as ready for review March 6, 2026 00:56
@dcantah dcantah merged commit 1be13d1 into apple:main Mar 6, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants