@@ -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 } ;
@@ -752,8 +753,11 @@ pub(crate) fn rollback_composefs_uki() -> Result<()> {
752753 let user_cfg_path = PathBuf :: from ( "/sysroot/boot/grub2" ) ;
753754
754755 let mut str = String :: new ( ) ;
756+ let boot_dir =
757+ cap_std:: fs:: Dir :: open_ambient_dir ( "/sysroot/boot" , cap_std:: ambient_authority ( ) )
758+ . context ( "Opening boot dir" ) ?;
755759 let mut menuentries =
756- get_sorted_uki_boot_entries ( & mut str) . context ( "Getting UKI boot entries" ) ?;
760+ get_sorted_uki_boot_entries ( & boot_dir , & mut str) . context ( "Getting UKI boot entries" ) ?;
757761
758762 // TODO(Johan-Liebert): Currently assuming there are only two deployments
759763 assert ! ( menuentries. len( ) == 2 ) ;
@@ -800,17 +804,25 @@ pub(crate) fn rollback_composefs_uki() -> Result<()> {
800804}
801805
802806// Need str to store lifetime
803- pub ( crate ) fn get_sorted_uki_boot_entries < ' a > ( str : & ' a mut String ) -> Result < Vec < MenuEntry < ' a > > > {
804- let mut file = std:: fs:: File :: open ( format ! ( "/sysroot/boot/grub2/{USER_CFG}" ) ) ?;
807+ pub ( crate ) fn get_sorted_uki_boot_entries < ' a > (
808+ boot_dir : & Dir ,
809+ str : & ' a mut String ,
810+ ) -> Result < Vec < MenuEntry < ' a > > > {
811+ let mut file = boot_dir
812+ . open ( format ! ( "grub2/{USER_CFG}" ) )
813+ . with_context ( || format ! ( "Opening {USER_CFG}" ) ) ?;
805814 file. read_to_string ( str) ?;
806815 parse_grub_menuentry_file ( str)
807816}
808817
809- #[ context( "Getting boot entries" ) ]
810- pub ( crate ) fn get_sorted_bls_boot_entries ( ascending : bool ) -> Result < Vec < BLSConfig > > {
818+ #[ context( "Getting sorted BLS entries" ) ]
819+ pub ( crate ) fn get_sorted_bls_boot_entries (
820+ boot_dir : & Dir ,
821+ ascending : bool ,
822+ ) -> Result < Vec < BLSConfig > > {
811823 let mut all_configs = vec ! [ ] ;
812824
813- for entry in std :: fs :: read_dir ( format ! ( "/sysroot/boot/ loader/{BOOT_LOADER_ENTRIES}" ) ) ? {
825+ for entry in boot_dir . read_dir ( format ! ( "loader/{BOOT_LOADER_ENTRIES}" ) ) ? {
814826 let entry = entry?;
815827
816828 let file_name = entry. file_name ( ) ;
@@ -823,8 +835,13 @@ pub(crate) fn get_sorted_bls_boot_entries(ascending: bool) -> Result<Vec<BLSConf
823835 continue ;
824836 }
825837
826- let contents = std:: fs:: read_to_string ( & entry. path ( ) )
827- . with_context ( || format ! ( "Failed to read {:?}" , entry. path( ) ) ) ?;
838+ let mut file = entry
839+ . open ( )
840+ . with_context ( || format ! ( "Failed to open {:?}" , file_name) ) ?;
841+
842+ let mut contents = String :: new ( ) ;
843+ file. read_to_string ( & mut contents)
844+ . with_context ( || format ! ( "Failed to read {:?}" , file_name) ) ?;
828845
829846 let config = parse_bls_config ( & contents) . context ( "Parsing bls config" ) ?;
830847
@@ -838,11 +855,15 @@ pub(crate) fn get_sorted_bls_boot_entries(ascending: bool) -> Result<Vec<BLSConf
838855
839856#[ context( "Rolling back BLS" ) ]
840857pub ( crate ) fn rollback_composefs_bls ( ) -> Result < ( ) > {
858+ let boot_dir =
859+ cap_std:: fs:: Dir :: open_ambient_dir ( "/sysroot/boot" , cap_std:: ambient_authority ( ) )
860+ . context ( "Opening boot dir" ) ?;
861+
841862 // Sort in descending order as that's the order they're shown on the boot screen
842863 // After this:
843864 // all_configs[0] -> booted depl
844865 // all_configs[1] -> rollback depl
845- let mut all_configs = get_sorted_bls_boot_entries ( false ) ?;
866+ let mut all_configs = get_sorted_bls_boot_entries ( & boot_dir , false ) ?;
846867
847868 // Update the indicies so that they're swapped
848869 for ( idx, cfg) in all_configs. iter_mut ( ) . enumerate ( ) {
0 commit comments