@@ -466,7 +466,7 @@ fn timestamp_of_manifest_or_config(
466466/// Automatically clean up files that may have been injected by container
467467/// builds. xref https://github.com/containers/buildah/issues/4242
468468fn cleanup_root ( root : & Dir ) -> Result < ( ) > {
469- const RUNTIME_INJECTED : & [ & str ] = & [ "etc/hostname" , "etc/resolv.conf" ] ;
469+ const RUNTIME_INJECTED : & [ & str ] = & [ "usr/ etc/hostname" , "usr/ etc/resolv.conf" ] ;
470470 for ent in RUNTIME_INJECTED {
471471 if let Some ( meta) = root. symlink_metadata_optional ( ent) ? {
472472 if meta. is_file ( ) && meta. size ( ) == 0 {
@@ -1055,15 +1055,16 @@ impl ImageImporter {
10551055 . with_context ( || format ! ( "Checking out layer {commit}" ) ) ?;
10561056 }
10571057
1058+ let root_dir = td. open_dir ( rootpath) ?;
1059+
10581060 let modifier =
10591061 ostree:: RepoCommitModifier :: new ( ostree:: RepoCommitModifierFlags :: CONSUME , None ) ;
10601062 modifier. set_devino_cache ( & devino) ;
10611063 // If we have derived layers, then we need to handle the case where
10621064 // the derived layers include custom policy. Just relabel everything
10631065 // in this case.
10641066 if have_derived_layers {
1065- let rootpath = td. open_dir ( rootpath) ?;
1066- let sepolicy = ostree:: SePolicy :: new_at ( rootpath. as_raw_fd ( ) , cancellable) ?;
1067+ let sepolicy = ostree:: SePolicy :: new_at ( root_dir. as_raw_fd ( ) , cancellable) ?;
10671068 tracing:: debug!( "labeling from merged tree" ) ;
10681069 modifier. set_sepolicy ( Some ( & sepolicy) ) ;
10691070 } else if let Some ( base) = base_commit. as_ref ( ) {
@@ -1074,7 +1075,7 @@ impl ImageImporter {
10741075 unreachable ! ( )
10751076 }
10761077
1077- cleanup_root ( & td ) ?;
1078+ cleanup_root ( & root_dir ) ?;
10781079
10791080 let mt = ostree:: MutableTree :: new ( ) ;
10801081 repo. write_dfd_to_mtree (
@@ -1965,23 +1966,24 @@ mod tests {
19651966 #[ test]
19661967 fn test_cleanup_root ( ) -> Result < ( ) > {
19671968 let td = cap_tempfile:: TempDir :: new ( cap_std:: ambient_authority ( ) ) ?;
1968-
1969+ let usretc = "usr/etc" ;
19691970 cleanup_root ( & td) . unwrap ( ) ;
1970- td. create_dir ( "etc" ) ?;
1971- td. write ( "etc/hostname" , b"hostname" ) ?;
1971+ td. create_dir_all ( usretc) ?;
1972+ let usretc = & td. open_dir ( usretc) ?;
1973+ usretc. write ( "hostname" , b"hostname" ) ?;
19721974 cleanup_root ( & td) . unwrap ( ) ;
1973- assert ! ( td . try_exists( "etc/ hostname" ) ?) ;
1974- td . write ( "etc/ hostname" , b"" ) ?;
1975+ assert ! ( usretc . try_exists( "hostname" ) ?) ;
1976+ usretc . write ( "hostname" , b"" ) ?;
19751977 cleanup_root ( & td) . unwrap ( ) ;
1976- assert ! ( !td. try_exists( "etc/ hostname" ) ?) ;
1978+ assert ! ( !td. try_exists( "hostname" ) ?) ;
19771979
1978- td . symlink_contents ( "../run/systemd/stub-resolv.conf" , "etc/ resolv.conf" ) ?;
1980+ usretc . symlink_contents ( "../run/systemd/stub-resolv.conf" , "resolv.conf" ) ?;
19791981 cleanup_root ( & td) . unwrap ( ) ;
1980- assert ! ( td . symlink_metadata( "etc/ resolv.conf" ) ?. is_symlink( ) ) ;
1981- td . remove_file ( "etc/ resolv.conf" ) ?;
1982- td . write ( "etc/ resolv.conf" , b"" ) ?;
1982+ assert ! ( usretc . symlink_metadata( "resolv.conf" ) ?. is_symlink( ) ) ;
1983+ usretc . remove_file ( "resolv.conf" ) ?;
1984+ usretc . write ( "resolv.conf" , b"" ) ?;
19831985 cleanup_root ( & td) . unwrap ( ) ;
1984- assert ! ( !td . try_exists( "etc/ resolv.conf" ) ?) ;
1986+ assert ! ( !usretc . try_exists( "resolv.conf" ) ?) ;
19851987
19861988 Ok ( ( ) )
19871989 }
0 commit comments