@@ -6,7 +6,8 @@ use bootc_kernel_cmdline::utf8::Cmdline;
6
6
use bootc_mount:: tempmount:: TempMount ;
7
7
use bootc_utils:: CommandRunExt ;
8
8
use 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 } ;
10
11
use composefs:: fsverity:: { FsVerityHashValue , Sha256HashValue } ;
11
12
use fn_error_context:: context;
12
13
@@ -17,41 +18,36 @@ use rustix::{
17
18
} ;
18
19
19
20
use crate :: bootc_composefs:: boot:: BootType ;
21
+ use crate :: bootc_composefs:: status:: get_sorted_type1_boot_entries;
20
22
use crate :: parsers:: bls_config:: BLSConfigType ;
21
23
use crate :: {
22
24
composefs_consts:: {
23
25
COMPOSEFS_CMDLINE , COMPOSEFS_STAGED_DEPLOYMENT_FNAME , COMPOSEFS_TRANSIENT_STATE_DIR ,
24
26
ORIGIN_KEY_BOOT , ORIGIN_KEY_BOOT_DIGEST , ORIGIN_KEY_BOOT_TYPE , SHARED_VAR_PATH ,
25
27
STATE_DIR_RELATIVE ,
26
28
} ,
27
- parsers:: bls_config:: { parse_bls_config , BLSConfig } ,
29
+ parsers:: bls_config:: BLSConfig ,
28
30
spec:: ImageReference ,
29
31
utils:: path_relative_to,
30
32
} ;
31
33
32
- pub ( crate ) fn get_booted_bls ( ) -> Result < BLSConfig > {
34
+ pub ( crate ) fn get_booted_bls ( boot_dir : & Dir ) -> Result < BLSConfig > {
33
35
let cmdline = Cmdline :: from_proc ( ) ?;
34
36
let booted = cmdline
35
37
. find ( COMPOSEFS_CMDLINE )
36
38
. ok_or_else ( || anyhow:: anyhow!( "Failed to find composefs parameter in kernel cmdline" ) ) ?;
37
39
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 ) ?;
40
41
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 {
48
44
BLSConfigType :: EFI { efi } => {
49
45
let composfs_param_value = booted. value ( ) . ok_or ( anyhow:: anyhow!(
50
46
"Failed to get composefs kernel cmdline value"
51
47
) ) ?;
52
48
53
49
if efi. contains ( composfs_param_value) {
54
- return Ok ( bls ) ;
50
+ return Ok ( entry ) ;
55
51
}
56
52
}
57
53
@@ -63,7 +59,7 @@ pub(crate) fn get_booted_bls() -> Result<BLSConfig> {
63
59
let opts = Cmdline :: from ( opts) ;
64
60
65
61
if opts. iter ( ) . any ( |v| v == booted) {
66
- return Ok ( bls ) ;
62
+ return Ok ( entry ) ;
67
63
}
68
64
}
69
65
@@ -151,8 +147,8 @@ pub(crate) fn write_composefs_state(
151
147
. item ( ORIGIN_KEY_BOOT_DIGEST , boot_digest) ;
152
148
}
153
149
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" ) ?;
156
152
157
153
state_dir
158
154
. atomic_write (
@@ -165,11 +161,9 @@ pub(crate) fn write_composefs_state(
165
161
std:: fs:: create_dir_all ( COMPOSEFS_TRANSIENT_STATE_DIR )
166
162
. with_context ( || format ! ( "Creating {COMPOSEFS_TRANSIENT_STATE_DIR}" ) ) ?;
167
163
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}" ) ) ?;
173
167
174
168
staged_depl_dir
175
169
. atomic_write (
0 commit comments