@@ -9,7 +9,7 @@ use bootc_utils::CommandRunExt;
99use camino:: Utf8PathBuf ;
1010use cap_std_ext:: cap_std:: ambient_authority;
1111use cap_std_ext:: cap_std:: fs:: Dir ;
12- use cap_std_ext:: { cap_std , dirext:: CapStdExtDirExt } ;
12+ use cap_std_ext:: dirext:: CapStdExtDirExt ;
1313use composefs:: fsverity:: { FsVerityHashValue , Sha256HashValue } ;
1414use fn_error_context:: context;
1515
@@ -20,41 +20,36 @@ use rustix::{
2020} ;
2121
2222use crate :: bootc_composefs:: boot:: BootType ;
23+ use crate :: bootc_composefs:: status:: get_sorted_type1_boot_entries;
2324use crate :: parsers:: bls_config:: BLSConfigType ;
2425use crate :: {
2526 composefs_consts:: {
2627 COMPOSEFS_CMDLINE , COMPOSEFS_STAGED_DEPLOYMENT_FNAME , COMPOSEFS_TRANSIENT_STATE_DIR ,
2728 ORIGIN_KEY_BOOT , ORIGIN_KEY_BOOT_DIGEST , ORIGIN_KEY_BOOT_TYPE , SHARED_VAR_PATH ,
2829 STATE_DIR_RELATIVE ,
2930 } ,
30- parsers:: bls_config:: { parse_bls_config , BLSConfig } ,
31+ parsers:: bls_config:: BLSConfig ,
3132 spec:: ImageReference ,
3233 utils:: path_relative_to,
3334} ;
3435
35- pub ( crate ) fn get_booted_bls ( ) -> Result < BLSConfig > {
36+ pub ( crate ) fn get_booted_bls ( boot_dir : & Dir ) -> Result < BLSConfig > {
3637 let cmdline = Cmdline :: from_proc ( ) ?;
3738 let booted = cmdline
3839 . find ( COMPOSEFS_CMDLINE )
3940 . ok_or_else ( || anyhow:: anyhow!( "Failed to find composefs parameter in kernel cmdline" ) ) ?;
4041
41- for entry in std:: fs:: read_dir ( "/sysroot/boot/loader/entries" ) ? {
42- let entry = entry?;
42+ let sorted_entries = get_sorted_type1_boot_entries ( boot_dir, true ) ?;
4343
44- if !entry. file_name ( ) . as_str ( ) ?. ends_with ( ".conf" ) {
45- continue ;
46- }
47-
48- let bls = parse_bls_config ( & std:: fs:: read_to_string ( & entry. path ( ) ) ?) ?;
49-
50- match & bls. cfg_type {
44+ for entry in sorted_entries {
45+ match & entry. cfg_type {
5146 BLSConfigType :: EFI { efi } => {
5247 let composfs_param_value = booted. value ( ) . ok_or ( anyhow:: anyhow!(
5348 "Failed to get composefs kernel cmdline value"
5449 ) ) ?;
5550
5651 if efi. contains ( composfs_param_value) {
57- return Ok ( bls ) ;
52+ return Ok ( entry ) ;
5853 }
5954 }
6055
@@ -66,7 +61,7 @@ pub(crate) fn get_booted_bls() -> Result<BLSConfig> {
6661 let opts = Cmdline :: from ( opts) ;
6762
6863 if opts. iter ( ) . any ( |v| v == booted) {
69- return Ok ( bls ) ;
64+ return Ok ( entry ) ;
7065 }
7166 }
7267
@@ -154,8 +149,8 @@ pub(crate) fn write_composefs_state(
154149 . item ( ORIGIN_KEY_BOOT_DIGEST , boot_digest) ;
155150 }
156151
157- let state_dir = cap_std :: fs :: Dir :: open_ambient_dir ( & state_path , cap_std :: ambient_authority ( ) )
158- . context ( "Opening state dir" ) ?;
152+ let state_dir =
153+ Dir :: open_ambient_dir ( & state_path , ambient_authority ( ) ) . context ( "Opening state dir" ) ?;
159154
160155 state_dir
161156 . atomic_write (
@@ -168,11 +163,9 @@ pub(crate) fn write_composefs_state(
168163 std:: fs:: create_dir_all ( COMPOSEFS_TRANSIENT_STATE_DIR )
169164 . with_context ( || format ! ( "Creating {COMPOSEFS_TRANSIENT_STATE_DIR}" ) ) ?;
170165
171- let staged_depl_dir = cap_std:: fs:: Dir :: open_ambient_dir (
172- COMPOSEFS_TRANSIENT_STATE_DIR ,
173- cap_std:: ambient_authority ( ) ,
174- )
175- . with_context ( || format ! ( "Opening {COMPOSEFS_TRANSIENT_STATE_DIR}" ) ) ?;
166+ let staged_depl_dir =
167+ Dir :: open_ambient_dir ( COMPOSEFS_TRANSIENT_STATE_DIR , ambient_authority ( ) )
168+ . with_context ( || format ! ( "Opening {COMPOSEFS_TRANSIENT_STATE_DIR}" ) ) ?;
176169
177170 staged_depl_dir
178171 . atomic_write (
0 commit comments