@@ -57,8 +57,14 @@ impl<'a, 'b, 'c> ContainerDataVolume<'a, 'b, 'c> {
5757 . run_and_get_status ( msg_info, false )
5858 }
5959
60- // copy files for a docker volume, for remote host support
61- // NOTE: `reldst` has the same caveats as `reldir` in `create_dir`.
60+ /// Copy files for a docker volume
61+ ///
62+ /// `reldst` has the same caveats as `reldir` in [`Self::create_dir`].
63+ ///
64+ /// ## Note
65+ ///
66+ /// if copying from a src directory to dst directory with docker, to
67+ /// copy the contents from `src` into `dst`, `src` must end with `/.`
6268 #[ track_caller]
6369 fn copy_files (
6470 & self ,
@@ -67,14 +73,33 @@ impl<'a, 'b, 'c> ContainerDataVolume<'a, 'b, 'c> {
6773 mount_prefix : & str ,
6874 msg_info : & mut MessageInfo ,
6975 ) -> Result < ExitStatus > {
76+ if let Some ( ( _, rel) ) = reldst. rsplit_once ( '/' ) {
77+ if msg_info. cross_debug
78+ && src. is_dir ( )
79+ && !src. to_string_lossy ( ) . ends_with ( "/." )
80+ && rel == src. file_name ( ) . unwrap ( )
81+ {
82+ msg_info. warn ( format_args ! (
83+ "source is pointing to a directory instead of its contents: {} -> {}\n This might be a bug. {}" ,
84+ src. as_posix_relative( ) ?,
85+ reldst,
86+ std:: panic:: Location :: caller( )
87+ ) ) ?;
88+ }
89+ }
7090 subcommand_or_exit ( self . engine , "cp" ) ?
7191 . arg ( "-a" )
7292 . arg ( src. to_utf8 ( ) ?)
7393 . arg ( format ! ( "{}:{mount_prefix}/{reldst}" , self . container) )
7494 . run_and_get_status ( msg_info, false )
7595 }
7696
77- // copy files for a docker volume, for remote host support
97+ /// copy files for a docker volume, does not include cache directories
98+ ///
99+ /// ## Note
100+ ///
101+ /// if copying from a src directory to dst directory with docker, to
102+ /// copy the contents from `src` into `dst`, `src` must end with `/.`
78103 #[ track_caller]
79104 fn copy_files_nocache (
80105 & self ,
@@ -114,8 +139,7 @@ impl<'a, 'b, 'c> ContainerDataVolume<'a, 'b, 'c> {
114139 file:: create_dir_all ( dst_path. parent ( ) . expect ( "must have parent" ) ) ?;
115140 fs:: copy ( src_path, & dst_path) ?;
116141 }
117- // if copying from a src directory to dst directory with docker, to
118- // copy the contents from `src` into `dst`, `src` must end with `/.`
142+
119143 self . copy_files ( & temppath. join ( "." ) , reldst, mount_prefix, msg_info)
120144 }
121145
@@ -196,7 +220,7 @@ impl<'a, 'b, 'c> ContainerDataVolume<'a, 'b, 'c> {
196220 mount_prefix,
197221 msg_info,
198222 ) ?;
199- self . copy_files ( dirs. xargo ( ) , & reldst, mount_prefix, msg_info) ?;
223+ self . copy_files ( & dirs. xargo ( ) . join ( "." ) , & reldst, mount_prefix, msg_info) ?;
200224 }
201225
202226 Ok ( ( ) )
@@ -215,11 +239,11 @@ impl<'a, 'b, 'c> ContainerDataVolume<'a, 'b, 'c> {
215239 . map ( |s| bool_from_envvar ( & s) )
216240 . unwrap_or ( copy_registry) ;
217241
242+ self . create_dir ( & reldst, mount_prefix, msg_info) ?;
218243 if copy_registry {
219- self . copy_files ( dirs. cargo ( ) , & reldst, mount_prefix, msg_info) ?;
244+ self . copy_files ( & dirs. cargo ( ) . join ( "." ) , & reldst, mount_prefix, msg_info) ?;
220245 } else {
221246 // can copy a limit subset of files: the rest is present.
222- self . create_dir ( & reldst, mount_prefix, msg_info) ?;
223247 for entry in fs:: read_dir ( dirs. cargo ( ) )
224248 . wrap_err_with ( || format ! ( "when reading directory {:?}" , dirs. cargo( ) ) ) ?
225249 {
@@ -380,9 +404,9 @@ impl<'a, 'b, 'c> ContainerDataVolume<'a, 'b, 'c> {
380404 ) -> Result < ( ) > {
381405 let copy_all = |info : & mut MessageInfo | {
382406 if copy_cache {
383- self . copy_files ( src, reldst, mount_prefix, info)
407+ self . copy_files ( & src. join ( "." ) , reldst, mount_prefix, info)
384408 } else {
385- self . copy_files_nocache ( src, reldst, mount_prefix, true , info)
409+ self . copy_files_nocache ( & src. join ( "." ) , reldst, mount_prefix, true , info)
386410 }
387411 } ;
388412 match volume {
0 commit comments