@@ -466,7 +466,7 @@ fn timestamp_of_manifest_or_config(
466
466
/// Automatically clean up files that may have been injected by container
467
467
/// builds. xref https://github.com/containers/buildah/issues/4242
468
468
fn 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" ] ;
470
470
for ent in RUNTIME_INJECTED {
471
471
if let Some ( meta) = root. symlink_metadata_optional ( ent) ? {
472
472
if meta. is_file ( ) && meta. size ( ) == 0 {
@@ -1055,15 +1055,16 @@ impl ImageImporter {
1055
1055
. with_context ( || format ! ( "Checking out layer {commit}" ) ) ?;
1056
1056
}
1057
1057
1058
+ let root_dir = td. open_dir ( rootpath) ?;
1059
+
1058
1060
let modifier =
1059
1061
ostree:: RepoCommitModifier :: new ( ostree:: RepoCommitModifierFlags :: CONSUME , None ) ;
1060
1062
modifier. set_devino_cache ( & devino) ;
1061
1063
// If we have derived layers, then we need to handle the case where
1062
1064
// the derived layers include custom policy. Just relabel everything
1063
1065
// in this case.
1064
1066
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) ?;
1067
1068
tracing:: debug!( "labeling from merged tree" ) ;
1068
1069
modifier. set_sepolicy ( Some ( & sepolicy) ) ;
1069
1070
} else if let Some ( base) = base_commit. as_ref ( ) {
@@ -1074,7 +1075,7 @@ impl ImageImporter {
1074
1075
unreachable ! ( )
1075
1076
}
1076
1077
1077
- cleanup_root ( & td ) ?;
1078
+ cleanup_root ( & root_dir ) ?;
1078
1079
1079
1080
let mt = ostree:: MutableTree :: new ( ) ;
1080
1081
repo. write_dfd_to_mtree (
@@ -1965,23 +1966,24 @@ mod tests {
1965
1966
#[ test]
1966
1967
fn test_cleanup_root ( ) -> Result < ( ) > {
1967
1968
let td = cap_tempfile:: TempDir :: new ( cap_std:: ambient_authority ( ) ) ?;
1968
-
1969
+ let usretc = "usr/etc" ;
1969
1970
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" ) ?;
1972
1974
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"" ) ?;
1975
1977
cleanup_root ( & td) . unwrap ( ) ;
1976
- assert ! ( !td. try_exists( "etc/ hostname" ) ?) ;
1978
+ assert ! ( !td. try_exists( "hostname" ) ?) ;
1977
1979
1978
- td . symlink_contents ( "../run/systemd/stub-resolv.conf" , "etc/ resolv.conf" ) ?;
1980
+ usretc . symlink_contents ( "../run/systemd/stub-resolv.conf" , "resolv.conf" ) ?;
1979
1981
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"" ) ?;
1983
1985
cleanup_root ( & td) . unwrap ( ) ;
1984
- assert ! ( !td . try_exists( "etc/ resolv.conf" ) ?) ;
1986
+ assert ! ( !usretc . try_exists( "resolv.conf" ) ?) ;
1985
1987
1986
1988
Ok ( ( ) )
1987
1989
}
0 commit comments