@@ -26,7 +26,8 @@ use ostree_ext::tokio_util::spawn_blocking_cancellable_flatten;
2626use rustix:: fs:: { fsync, renameat_with, AtFlags , RenameFlags } ;
2727
2828use crate :: composefs_consts:: {
29- BOOT_LOADER_ENTRIES , ROLLBACK_BOOT_LOADER_ENTRIES , USER_CFG , USER_CFG_ROLLBACK ,
29+ BOOT_LOADER_ENTRIES , ROLLBACK_BOOT_LOADER_ENTRIES , USER_CFG ,
30+ USER_CFG_ROLLBACK ,
3031} ;
3132use crate :: install:: { get_efi_uuid_source, BootType } ;
3233use crate :: parsers:: bls_config:: { parse_bls_config, BLSConfig } ;
@@ -760,8 +761,11 @@ pub(crate) fn rollback_composefs_uki() -> Result<()> {
760761 let user_cfg_path = PathBuf :: from ( "/sysroot/boot/grub2" ) ;
761762
762763 let mut str = String :: new ( ) ;
764+ let boot_dir =
765+ cap_std:: fs:: Dir :: open_ambient_dir ( "/sysroot/boot" , cap_std:: ambient_authority ( ) )
766+ . context ( "Opening boot dir" ) ?;
763767 let mut menuentries =
764- get_sorted_uki_boot_entries ( & mut str) . context ( "Getting UKI boot entries" ) ?;
768+ get_sorted_uki_boot_entries ( & boot_dir , & mut str) . context ( "Getting UKI boot entries" ) ?;
765769
766770 // TODO(Johan-Liebert): Currently assuming there are only two deployments
767771 assert ! ( menuentries. len( ) == 2 ) ;
@@ -808,17 +812,25 @@ pub(crate) fn rollback_composefs_uki() -> Result<()> {
808812}
809813
810814// Need str to store lifetime
811- pub ( crate ) fn get_sorted_uki_boot_entries < ' a > ( str : & ' a mut String ) -> Result < Vec < MenuEntry < ' a > > > {
812- let mut file = std:: fs:: File :: open ( format ! ( "/sysroot/boot/grub2/{USER_CFG}" ) ) ?;
815+ pub ( crate ) fn get_sorted_uki_boot_entries < ' a > (
816+ boot_dir : & Dir ,
817+ str : & ' a mut String ,
818+ ) -> Result < Vec < MenuEntry < ' a > > > {
819+ let mut file = boot_dir
820+ . open ( format ! ( "grub2/{USER_CFG}" ) )
821+ . with_context ( || format ! ( "Opening {USER_CFG}" ) ) ?;
813822 file. read_to_string ( str) ?;
814823 parse_grub_menuentry_file ( str)
815824}
816825
817- #[ context( "Getting boot entries" ) ]
818- pub ( crate ) fn get_sorted_bls_boot_entries ( ascending : bool ) -> Result < Vec < BLSConfig > > {
826+ #[ context( "Getting sorted BLS entries" ) ]
827+ pub ( crate ) fn get_sorted_bls_boot_entries (
828+ boot_dir : & Dir ,
829+ ascending : bool ,
830+ ) -> Result < Vec < BLSConfig > > {
819831 let mut all_configs = vec ! [ ] ;
820832
821- for entry in std :: fs :: read_dir ( format ! ( "/sysroot/boot/ loader/{BOOT_LOADER_ENTRIES}" ) ) ? {
833+ for entry in boot_dir . read_dir ( format ! ( "loader/{BOOT_LOADER_ENTRIES}" ) ) ? {
822834 let entry = entry?;
823835
824836 let file_name = entry. file_name ( ) ;
@@ -831,8 +843,13 @@ pub(crate) fn get_sorted_bls_boot_entries(ascending: bool) -> Result<Vec<BLSConf
831843 continue ;
832844 }
833845
834- let contents = std:: fs:: read_to_string ( & entry. path ( ) )
835- . with_context ( || format ! ( "Failed to read {:?}" , entry. path( ) ) ) ?;
846+ let mut file = entry
847+ . open ( )
848+ . with_context ( || format ! ( "Failed to open {:?}" , file_name) ) ?;
849+
850+ let mut contents = String :: new ( ) ;
851+ file. read_to_string ( & mut contents)
852+ . with_context ( || format ! ( "Failed to read {:?}" , file_name) ) ?;
836853
837854 let config = parse_bls_config ( & contents) . context ( "Parsing bls config" ) ?;
838855
@@ -846,11 +863,15 @@ pub(crate) fn get_sorted_bls_boot_entries(ascending: bool) -> Result<Vec<BLSConf
846863
847864#[ context( "Rolling back BLS" ) ]
848865pub ( crate ) fn rollback_composefs_bls ( ) -> Result < ( ) > {
866+ let boot_dir =
867+ cap_std:: fs:: Dir :: open_ambient_dir ( "/sysroot/boot" , cap_std:: ambient_authority ( ) )
868+ . context ( "Opening boot dir" ) ?;
869+
849870 // Sort in descending order as that's the order they're shown on the boot screen
850871 // After this:
851872 // all_configs[0] -> booted depl
852873 // all_configs[1] -> rollback depl
853- let mut all_configs = get_sorted_bls_boot_entries ( false ) ?;
874+ let mut all_configs = get_sorted_bls_boot_entries ( & boot_dir , false ) ?;
854875
855876 // Update the indicies so that they're swapped
856877 for ( idx, cfg) in all_configs. iter_mut ( ) . enumerate ( ) {
0 commit comments