@@ -29,7 +29,7 @@ use atty::Stream;
2929use rand:: prelude:: * ;
3030use rand_chacha:: ChaCha20Rng ;
3131
32- use flakes:: user:: { User , mkdir} ;
32+ use flakes:: user:: { User , mkdir, cp , exists } ;
3333use flakes:: lookup:: Lookup ;
3434use flakes:: io:: IO ;
3535use flakes:: error:: FlakeError ;
@@ -49,6 +49,7 @@ use std::io::SeekFrom;
4949
5050use spinoff:: { Spinner , spinners, Color } ;
5151use tempfile:: tempfile;
52+ use tempfile:: NamedTempFile ;
5253use regex:: Regex ;
5354
5455use uzers:: { get_current_username} ;
@@ -151,7 +152,7 @@ pub fn create(
151152 mkdir ( defaults:: FLAKES_REGISTRY , "777" , User :: ROOT ) ?;
152153
153154 let current_user = get_current_username ( ) . unwrap ( ) ;
154- let user = User :: from ( current_user . to_str ( ) . unwrap ( ) ) ;
155+ let user = User :: from ( "root" ) ;
155156
156157 let container_cid_file = format ! (
157158 "{}/{}{}_{}.cid" ,
@@ -477,36 +478,35 @@ pub fn start(program_name: &str, cid: &str) -> Result<(), FlakeError> {
477478 let RuntimeSection { resume, attach, .. } = config ( ) . runtime ( ) ;
478479
479480 let pilot_options = Lookup :: get_pilot_run_options ( ) ;
480- let current_user = get_current_username ( ) . unwrap ( ) ;
481- let user = User :: from ( current_user. to_str ( ) . unwrap ( ) ) ;
481+ let root_user = User :: from ( "root" ) ;
482482
483- let is_running = container_running ( cid, user ) ?;
484- let is_created = container_exists ( cid, user ) ?;
483+ let is_running = container_running ( cid, root_user ) ?;
484+ let is_created = container_exists ( cid, root_user ) ?;
485485 let mut is_removed = false ;
486486
487487 if is_running {
488488 if attach {
489489 // 1. Attach to running container
490- call_instance ( "attach" , cid, program_name, user ) ?;
490+ call_instance ( "attach" , cid, program_name, root_user ) ?;
491491 } else {
492492 // 2. Execute app in running container
493- call_instance ( "exec" , cid, program_name, user ) ?;
493+ call_instance ( "exec" , cid, program_name, root_user ) ?;
494494 }
495495 } else if resume {
496496 // 3. Startup resume type container and execute app
497- call_instance ( "start" , cid, program_name, user ) ?;
498- call_instance ( "exec" , cid, program_name, user ) ?;
497+ call_instance ( "start" , cid, program_name, root_user ) ?;
498+ call_instance ( "exec" , cid, program_name, root_user ) ?;
499499 } else {
500500 // 4. Startup container
501- call_instance ( "start" , cid, program_name, user ) ?;
501+ call_instance ( "start" , cid, program_name, root_user ) ?;
502502 if ! attach || ! is_created {
503- call_instance ( "rm_force" , cid, program_name, user ) ?;
503+ call_instance ( "rm_force" , cid, program_name, root_user ) ?;
504504 is_removed = true
505505 }
506506 } ;
507507
508508 if pilot_options. contains_key ( "%remove" ) && ! is_removed {
509- call_instance ( "rm_force" , cid, program_name, user ) ?;
509+ call_instance ( "rm_force" , cid, program_name, root_user ) ?;
510510 } ;
511511 Ok ( ( ) )
512512}
@@ -641,6 +641,7 @@ pub fn sync_host(
641641 !*/
642642 let mut removed_files_contents = String :: new ( ) ;
643643 let files_from = format ! ( "{}/{}" , & target, from) ;
644+ let mut temp_files_from = NamedTempFile :: new ( ) ?;
644645 removed_files. seek ( SeekFrom :: Start ( 0 ) ) ?;
645646 removed_files. read_to_string ( & mut removed_files_contents) ?;
646647
@@ -650,8 +651,8 @@ pub fn sync_host(
650651 }
651652 return Ok ( ( ) )
652653 }
653-
654- File :: create ( & files_from ) ? . write_all ( removed_files_contents . as_bytes ( ) ) ?;
654+ temp_files_from . write_all ( removed_files_contents . as_bytes ( ) ) ? ;
655+ cp ( temp_files_from . path ( ) . to_str ( ) . unwrap ( ) , & files_from , User :: ROOT ) ?;
655656
656657 let mut call = user. run ( "rsync" ) ;
657658 call. arg ( "-av" ) ;
@@ -863,7 +864,7 @@ pub fn build_system_dependencies(
863864 to be provisioned from the host
864865 !*/
865866 let system_deps = format ! ( "{}/{}" , & target, dependency_file) ;
866- if Path :: new ( & system_deps) . exists ( ) {
867+ if exists ( & system_deps, User :: ROOT ) ? {
867868 if Lookup :: is_debug ( ) {
868869 debug ! ( "Calling system deps generator: {system_deps}" ) ;
869870 }
@@ -907,17 +908,19 @@ pub fn build_system_dependencies(
907908
908909pub fn update_removed_files (
909910 target : & String , mut accumulated_file : & File
910- ) -> Result < ( ) , std :: io :: Error > {
911+ ) -> Result < ( ) , FlakeError > {
911912 /*!
912913 Take the contents of the given removed_file and append it
913914 to the accumulated_file
914915 !*/
915916 let host_deps = format ! ( "{}/{}" , & target, defaults:: HOST_DEPENDENCIES ) ;
916- if Path :: new ( & host_deps) . exists ( ) {
917+ if exists ( & host_deps, User :: ROOT ) ? {
917918 if Lookup :: is_debug ( ) {
918919 debug ! ( "Adding host deps from {host_deps}" ) ;
919920 }
920- let data = fs:: read_to_string ( & host_deps) ?;
921+ let temp_host_deps = NamedTempFile :: new ( ) ?;
922+ cp ( & host_deps, temp_host_deps. path ( ) . to_str ( ) . unwrap ( ) , User :: ROOT ) ?;
923+ let data = fs:: read_to_string ( temp_host_deps. path ( ) ) ?;
921924 // The subsequent rsync call logs enough information
922925 // Let's keep this for convenience debugging
923926 // if Lookup::is_debug() {
0 commit comments