diff options
author | Dustin Frisch <fooker@lab.sh> | 2021-01-09 16:02:59 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-09 10:02:59 -0500 |
commit | b35a13a3985402898b726f660c470fefb64f2771 (patch) | |
tree | f7dc8e4eb936da9a8f0ec9619314c156c9ef29ab /src | |
parent | 17651193edad67f10f9e139d5b86b2d31665c0a6 (diff) |
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>
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 18 |
1 files changed, 15 insertions, 3 deletions
@@ -630,16 +630,28 @@ impl<'a> Container<'a> { .unwrap(); let data = ar.into_inner().unwrap(); - let body = Some((data, "application/x-tar".parse::<Mime>().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::<Mime>().unwrap(); + self.docker .put( &format!("/containers/{}/archive?{}", self.id, path_arg), - body.map(|(body, mime)| (body.into(), mime)), + Some((body, mime)), ) .await?; Ok(()) |