From b35a13a3985402898b726f660c470fefb64f2771 Mon Sep 17 00:00:00 2001 From: Dustin Frisch Date: Sat, 9 Jan 2021 16:02:59 +0100 Subject: Implement upload of tar to container (#239) * Implement upload of tar to container * Fixed typo Co-authored-by: Eli W. Hunter <42009212+elihunter173@users.noreply.github.com> Co-authored-by: Eli W. Hunter <42009212+elihunter173@users.noreply.github.com> --- src/lib.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index c810ea5..7d62523 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -630,16 +630,28 @@ impl<'a> Container<'a> { .unwrap(); let data = ar.into_inner().unwrap(); - let body = Some((data, "application/x-tar".parse::().unwrap())); + self.copy_to(Path::new("/"), data.into()).await?; + Ok(()) + } + /// Copy a tarball (see `body`) to the container. + /// + /// The tarball will be copied to the container and extracted at the given location (see `path`). + pub async fn copy_to( + &self, + path: &Path, + body: Body, + ) -> Result<()> { let path_arg = form_urlencoded::Serializer::new(String::new()) - .append_pair("path", "/") + .append_pair("path", &path.to_string_lossy()) .finish(); + let mime = "application/x-tar".parse::().unwrap(); + self.docker .put( &format!("/containers/{}/archive?{}", self.id, path_arg), - body.map(|(body, mime)| (body.into(), mime)), + Some((body, mime)), ) .await?; Ok(()) -- cgit v1.2.3