@@ -114,36 +114,34 @@ fn rollback_grub_uki_entries(boot_dir: &Dir) -> Result<()> {
114114/// - Grub Type1 boot entries
115115/// - Systemd Typ1 boot entries
116116/// - Systemd UKI (Type2) boot entries [since we use BLS entries for systemd boot]
117+ ///
118+ /// Cases
119+ /// 1. We're actually booted into the deployment that has it's sort_key as 0
120+ /// a. Just swap the primary and secondary bootloader entries
121+ /// b. If they're already swapped (rollback was queued), re-swap them (unqueue rollback)
122+ ///
123+ /// 2. We're booted into the depl with sort_key 1 (choose the rollback deployment on boot screen)
124+ /// a. Here we assume that rollback is queued as there's no way to differentiate between this
125+ /// case and Case 1-b. This is what ostree does as well
117126#[ context( "Rolling back {bootloader} entries" ) ]
118127fn rollback_composefs_entries ( boot_dir : & Dir , bootloader : Bootloader ) -> Result < ( ) > {
119- use crate :: bootc_composefs:: state:: get_booted_bls;
120-
121128 // Get all boot entries sorted in descending order by sort-key
122129 let mut all_configs = get_sorted_type1_boot_entries ( & boot_dir, false ) ?;
123130
124131 // TODO(Johan-Liebert): Currently assuming there are only two deployments
125132 assert ! ( all_configs. len( ) == 2 ) ;
126133
127- // Identify which entry is the currently booted one
128- let booted_bls = get_booted_bls ( & boot_dir) ?;
129- let booted_verity = booted_bls. get_verity ( ) ?;
130-
131134 // For rollback: previous gets primary sort-key, booted gets secondary sort-key
132135 // Use "bootc" as default os_id for rollback scenarios
133136 // TODO: Extract actual os_id from deployment
134137 let os_id = "bootc" ;
135138
136- for cfg in & mut all_configs {
137- let cfg_verity = cfg. get_verity ( ) ?;
138-
139- if cfg_verity == booted_verity {
140- // This is the currently booted deployment - it should become secondary
141- cfg. sort_key = Some ( secondary_sort_key ( os_id) ) ;
142- } else {
143- // This is the previous deployment - it should become primary (rollback target)
144- cfg. sort_key = Some ( primary_sort_key ( os_id) ) ;
145- }
146- }
139+ // This is the currently booted deployment - it should become secondary
140+ // OR if rollback was queued, it would become primary
141+ all_configs[ 0 ] . sort_key = Some ( primary_sort_key ( os_id) ) ;
142+ // This is the previous deployment - it should become primary (rollback target)
143+ // OR if rollback was queued, it would become secondary
144+ all_configs[ 1 ] . sort_key = Some ( secondary_sort_key ( os_id) ) ;
147145
148146 // Write these
149147 boot_dir
@@ -156,9 +154,8 @@ fn rollback_composefs_entries(boot_dir: &Dir, bootloader: Bootloader) -> Result<
156154
157155 // Write the BLS configs in there
158156 for cfg in all_configs {
159- let cfg_verity = cfg. get_verity ( ) ?;
160157 // After rollback: previous deployment becomes primary, booted becomes secondary
161- let priority = if cfg_verity == booted_verity {
158+ let priority = if cfg . sort_key == Some ( secondary_sort_key ( os_id ) ) {
162159 FILENAME_PRIORITY_SECONDARY
163160 } else {
164161 FILENAME_PRIORITY_PRIMARY
0 commit comments