From 12ec796a5c9cdc1803f59c85328456538c698cbe Mon Sep 17 00:00:00 2001 From: Marc Schreiber Date: Sat, 1 Jun 2019 07:17:25 +0200 Subject: copy_file_into creates sub-directories if required (#171) --- src/lib.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 4c324ce..669ac42 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -543,8 +543,7 @@ impl<'a, 'b> Container<'a, 'b> { /// Copy a byte slice as file into (see `bytes`) the container. /// /// The file will be copied at the given location (see `path`) and will be owned by root - /// with access mask 644. The specified `path` parent location must exists, otherwise the - /// creation of the file fails. + /// with access mask 644. pub fn copy_file_into>( &self, path: P, @@ -558,7 +557,10 @@ impl<'a, 'b> Container<'a, 'b> { header.set_mode(0o0644); ar.append_data( &mut header, - path.file_name().map(|f| f.to_str().unwrap()).unwrap(), + path.to_path_buf() + .iter() + .skip(1) + .collect::(), bytes, ) .unwrap(); @@ -567,7 +569,7 @@ impl<'a, 'b> Container<'a, 'b> { let body = Some((data, "application/x-tar".parse::().unwrap())); let path_arg = form_urlencoded::Serializer::new(String::new()) - .append_pair("path", &path.parent().map(|p| p.to_string_lossy()).unwrap()) + .append_pair("path", "/") .finish(); self.docker -- cgit v1.2.3