@@ -240,17 +240,9 @@ impl<'a> VolumeApi<'a> {
240240 volume_file : VolumeFilesSpec ,
241241 uid : Option < & str > ,
242242 ) -> Result < ( ) , AnyError > {
243- self . ensure_file (
244- volume_file. volume_name . as_str ( ) ,
243+ self . ensure_file_v2 (
245244 target_dir. as_str ( ) ,
246- & volume_file. clone ( )
247- . files
248- . into_iter ( )
249- . map ( |file| RoozVolumeFile {
250- file_path : file. target_file . as_str ( ) . to_string ( ) ,
251- data : file. content ,
252- } )
253- . collect :: < Vec < _ > > ( ) ,
245+ & volume_file. clone ( ) ,
254246 Self :: mount ( & target_dir, & volume_file) ,
255247 uid,
256248 )
@@ -370,6 +362,55 @@ impl<'a> VolumeApi<'a> {
370362 Ok ( mount)
371363 }
372364
365+ async fn ensure_file_v2 (
366+ & self ,
367+ root_dir : & str ,
368+ spec : & VolumeFilesSpec ,
369+ mount : Mount ,
370+ uid : Option < & str > ,
371+ ) -> Result < ( ) , AnyError > {
372+ let mut cmd = spec
373+ . files
374+ . iter ( )
375+ . map ( |f| {
376+ let parent_dir = Path :: new ( f. target_file . as_str ( ) )
377+ . parent ( )
378+ . unwrap ( )
379+ . to_string_lossy ( )
380+ . into_owned ( ) ;
381+
382+ format ! (
383+ "mkdir -p {} && echo '{}' | base64 -d > {}" ,
384+ parent_dir,
385+ general_purpose:: STANDARD . encode( f. content. trim( ) ) ,
386+ f. target_file. as_str( ) ,
387+ )
388+ } )
389+ . collect :: < Vec < _ > > ( )
390+ . join ( " && " . into ( ) ) ;
391+
392+ if let Some ( uid) = uid {
393+ let chown = format ! ( "chown -R {}:{} {}" , uid, uid, root_dir) ;
394+ cmd = format ! (
395+ "{}{}{}" ,
396+ cmd,
397+ if cmd. is_empty( ) { "" } else { " && " } ,
398+ chown
399+ )
400+ }
401+
402+ self . container
403+ . one_shot (
404+ & format ! ( "populate volume: {}" , & spec. volume_name. as_str( ) ) ,
405+ cmd,
406+ Some ( vec ! [ mount] ) ,
407+ None ,
408+ None ,
409+ )
410+ . await ?;
411+
412+ Ok ( ( ) )
413+ }
373414 async fn ensure_file (
374415 & self ,
375416 volume_name : & str ,
@@ -386,8 +427,7 @@ impl<'a> VolumeApi<'a> {
386427 . to_string_lossy ( )
387428 . to_string ( ) ;
388429 format ! (
389- "mkdir -p {} && echo '{}' | base64 -d > {}" ,
390- parent_dir,
430+ "echo '{}' | base64 -d > {}" ,
391431 general_purpose:: STANDARD . encode( f. data. trim( ) ) ,
392432 p,
393433 )
0 commit comments