@@ -6,7 +6,8 @@ use bootc_kernel_cmdline::utf8::Cmdline;
66use bootc_mount:: tempmount:: TempMount ;
77use bootc_utils:: CommandRunExt ;
88use camino:: Utf8PathBuf ;
9- use cap_std_ext:: { cap_std, dirext:: CapStdExtDirExt } ;
9+ use cap_std_ext:: cap_std:: ambient_authority;
10+ use cap_std_ext:: { cap_std:: fs:: Dir , dirext:: CapStdExtDirExt } ;
1011use composefs:: fsverity:: { FsVerityHashValue , Sha256HashValue } ;
1112use fn_error_context:: context;
1213
@@ -17,41 +18,36 @@ use rustix::{
1718} ;
1819
1920use crate :: bootc_composefs:: boot:: BootType ;
21+ use crate :: bootc_composefs:: status:: get_sorted_type1_boot_entries;
2022use crate :: parsers:: bls_config:: BLSConfigType ;
2123use crate :: {
2224 composefs_consts:: {
2325 COMPOSEFS_CMDLINE , COMPOSEFS_STAGED_DEPLOYMENT_FNAME , COMPOSEFS_TRANSIENT_STATE_DIR ,
2426 ORIGIN_KEY_BOOT , ORIGIN_KEY_BOOT_DIGEST , ORIGIN_KEY_BOOT_TYPE , SHARED_VAR_PATH ,
2527 STATE_DIR_RELATIVE ,
2628 } ,
27- parsers:: bls_config:: { parse_bls_config , BLSConfig } ,
29+ parsers:: bls_config:: BLSConfig ,
2830 spec:: ImageReference ,
2931 utils:: path_relative_to,
3032} ;
3133
32- pub ( crate ) fn get_booted_bls ( ) -> Result < BLSConfig > {
34+ pub ( crate ) fn get_booted_bls ( boot_dir : & Dir ) -> Result < BLSConfig > {
3335 let cmdline = Cmdline :: from_proc ( ) ?;
3436 let booted = cmdline
3537 . find ( COMPOSEFS_CMDLINE )
3638 . ok_or_else ( || anyhow:: anyhow!( "Failed to find composefs parameter in kernel cmdline" ) ) ?;
3739
38- for entry in std:: fs:: read_dir ( "/sysroot/boot/loader/entries" ) ? {
39- let entry = entry?;
40+ let sorted_entries = get_sorted_type1_boot_entries ( boot_dir, true ) ?;
4041
41- if !entry. file_name ( ) . as_str ( ) ?. ends_with ( ".conf" ) {
42- continue ;
43- }
44-
45- let bls = parse_bls_config ( & std:: fs:: read_to_string ( & entry. path ( ) ) ?) ?;
46-
47- match & bls. cfg_type {
42+ for entry in sorted_entries {
43+ match & entry. cfg_type {
4844 BLSConfigType :: EFI { efi } => {
4945 let composfs_param_value = booted. value ( ) . ok_or ( anyhow:: anyhow!(
5046 "Failed to get composefs kernel cmdline value"
5147 ) ) ?;
5248
5349 if efi. contains ( composfs_param_value) {
54- return Ok ( bls ) ;
50+ return Ok ( entry ) ;
5551 }
5652 }
5753
@@ -63,7 +59,7 @@ pub(crate) fn get_booted_bls() -> Result<BLSConfig> {
6359 let opts = Cmdline :: from ( opts) ;
6460
6561 if opts. iter ( ) . any ( |v| v == booted) {
66- return Ok ( bls ) ;
62+ return Ok ( entry ) ;
6763 }
6864 }
6965
@@ -151,8 +147,8 @@ pub(crate) fn write_composefs_state(
151147 . item ( ORIGIN_KEY_BOOT_DIGEST , boot_digest) ;
152148 }
153149
154- let state_dir = cap_std :: fs :: Dir :: open_ambient_dir ( & state_path , cap_std :: ambient_authority ( ) )
155- . context ( "Opening state dir" ) ?;
150+ let state_dir =
151+ Dir :: open_ambient_dir ( & state_path , ambient_authority ( ) ) . context ( "Opening state dir" ) ?;
156152
157153 state_dir
158154 . atomic_write (
@@ -165,11 +161,9 @@ pub(crate) fn write_composefs_state(
165161 std:: fs:: create_dir_all ( COMPOSEFS_TRANSIENT_STATE_DIR )
166162 . with_context ( || format ! ( "Creating {COMPOSEFS_TRANSIENT_STATE_DIR}" ) ) ?;
167163
168- let staged_depl_dir = cap_std:: fs:: Dir :: open_ambient_dir (
169- COMPOSEFS_TRANSIENT_STATE_DIR ,
170- cap_std:: ambient_authority ( ) ,
171- )
172- . with_context ( || format ! ( "Opening {COMPOSEFS_TRANSIENT_STATE_DIR}" ) ) ?;
164+ let staged_depl_dir =
165+ Dir :: open_ambient_dir ( COMPOSEFS_TRANSIENT_STATE_DIR , ambient_authority ( ) )
166+ . with_context ( || format ! ( "Opening {COMPOSEFS_TRANSIENT_STATE_DIR}" ) ) ?;
173167
174168 staged_depl_dir
175169 . atomic_write (
0 commit comments