@@ -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 } ;
@@ -755,8 +756,11 @@ pub(crate) fn rollback_composefs_uki() -> Result<()> {
755756 let user_cfg_path = PathBuf :: from ( "/sysroot/boot/grub2" ) ;
756757
757758 let mut str = String :: new ( ) ;
759+ let boot_dir =
760+ cap_std:: fs:: Dir :: open_ambient_dir ( "/sysroot/boot" , cap_std:: ambient_authority ( ) )
761+ . context ( "Opening boot dir" ) ?;
758762 let mut menuentries =
759- get_sorted_uki_boot_entries ( & mut str) . context ( "Getting UKI boot entries" ) ?;
763+ get_sorted_uki_boot_entries ( & boot_dir , & mut str) . context ( "Getting UKI boot entries" ) ?;
760764
761765 // TODO(Johan-Liebert): Currently assuming there are only two deployments
762766 assert ! ( menuentries. len( ) == 2 ) ;
@@ -803,17 +807,25 @@ pub(crate) fn rollback_composefs_uki() -> Result<()> {
803807}
804808
805809// Need str to store lifetime
806- pub ( crate ) fn get_sorted_uki_boot_entries < ' a > ( str : & ' a mut String ) -> Result < Vec < MenuEntry < ' a > > > {
807- let mut file = std:: fs:: File :: open ( format ! ( "/sysroot/boot/grub2/{USER_CFG}" ) ) ?;
810+ pub ( crate ) fn get_sorted_uki_boot_entries < ' a > (
811+ boot_dir : & Dir ,
812+ str : & ' a mut String ,
813+ ) -> Result < Vec < MenuEntry < ' a > > > {
814+ let mut file = boot_dir
815+ . open ( format ! ( "grub2/{USER_CFG}" ) )
816+ . with_context ( || format ! ( "Opening {USER_CFG}" ) ) ?;
808817 file. read_to_string ( str) ?;
809818 parse_grub_menuentry_file ( str)
810819}
811820
812- #[ context( "Getting boot entries" ) ]
813- pub ( crate ) fn get_sorted_bls_boot_entries ( ascending : bool ) -> Result < Vec < BLSConfig > > {
821+ #[ context( "Getting sorted BLS entries" ) ]
822+ pub ( crate ) fn get_sorted_bls_boot_entries (
823+ boot_dir : & Dir ,
824+ ascending : bool ,
825+ ) -> Result < Vec < BLSConfig > > {
814826 let mut all_configs = vec ! [ ] ;
815827
816- for entry in std :: fs :: read_dir ( format ! ( "/sysroot/boot/ loader/{BOOT_LOADER_ENTRIES}" ) ) ? {
828+ for entry in boot_dir . read_dir ( format ! ( "loader/{BOOT_LOADER_ENTRIES}" ) ) ? {
817829 let entry = entry?;
818830
819831 let file_name = entry. file_name ( ) ;
@@ -826,8 +838,13 @@ pub(crate) fn get_sorted_bls_boot_entries(ascending: bool) -> Result<Vec<BLSConf
826838 continue ;
827839 }
828840
829- let contents = std:: fs:: read_to_string ( & entry. path ( ) )
830- . with_context ( || format ! ( "Failed to read {:?}" , entry. path( ) ) ) ?;
841+ let mut file = entry
842+ . open ( )
843+ . with_context ( || format ! ( "Failed to open {:?}" , file_name) ) ?;
844+
845+ let mut contents = String :: new ( ) ;
846+ file. read_to_string ( & mut contents)
847+ . with_context ( || format ! ( "Failed to read {:?}" , file_name) ) ?;
831848
832849 let config = parse_bls_config ( & contents) . context ( "Parsing bls config" ) ?;
833850
@@ -841,11 +858,15 @@ pub(crate) fn get_sorted_bls_boot_entries(ascending: bool) -> Result<Vec<BLSConf
841858
842859#[ context( "Rolling back BLS" ) ]
843860pub ( crate ) fn rollback_composefs_bls ( ) -> Result < ( ) > {
861+ let boot_dir =
862+ cap_std:: fs:: Dir :: open_ambient_dir ( "/sysroot/boot" , cap_std:: ambient_authority ( ) )
863+ . context ( "Opening boot dir" ) ?;
864+
844865 // Sort in descending order as that's the order they're shown on the boot screen
845866 // After this:
846867 // all_configs[0] -> booted depl
847868 // all_configs[1] -> rollback depl
848- let mut all_configs = get_sorted_bls_boot_entries ( false ) ?;
869+ let mut all_configs = get_sorted_bls_boot_entries ( & boot_dir , false ) ?;
849870
850871 // Update the indicies so that they're swapped
851872 for ( idx, cfg) in all_configs. iter_mut ( ) . enumerate ( ) {
0 commit comments