@@ -26,7 +26,8 @@ use ostree_ext::tokio_util::spawn_blocking_cancellable_flatten;
26
26
use rustix:: fs:: { fsync, renameat_with, AtFlags , RenameFlags } ;
27
27
28
28
use 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 ,
30
31
} ;
31
32
use crate :: install:: { get_efi_uuid_source, BootType } ;
32
33
use crate :: parsers:: bls_config:: { parse_bls_config, BLSConfig } ;
@@ -755,8 +756,11 @@ pub(crate) fn rollback_composefs_uki() -> Result<()> {
755
756
let user_cfg_path = PathBuf :: from ( "/sysroot/boot/grub2" ) ;
756
757
757
758
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" ) ?;
758
762
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" ) ?;
760
764
761
765
// TODO(Johan-Liebert): Currently assuming there are only two deployments
762
766
assert ! ( menuentries. len( ) == 2 ) ;
@@ -803,17 +807,25 @@ pub(crate) fn rollback_composefs_uki() -> Result<()> {
803
807
}
804
808
805
809
// 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}" ) ) ?;
808
817
file. read_to_string ( str) ?;
809
818
parse_grub_menuentry_file ( str)
810
819
}
811
820
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 > > {
814
826
let mut all_configs = vec ! [ ] ;
815
827
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}" ) ) ? {
817
829
let entry = entry?;
818
830
819
831
let file_name = entry. file_name ( ) ;
@@ -826,8 +838,13 @@ pub(crate) fn get_sorted_bls_boot_entries(ascending: bool) -> Result<Vec<BLSConf
826
838
continue ;
827
839
}
828
840
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) ) ?;
831
848
832
849
let config = parse_bls_config ( & contents) . context ( "Parsing bls config" ) ?;
833
850
@@ -841,11 +858,15 @@ pub(crate) fn get_sorted_bls_boot_entries(ascending: bool) -> Result<Vec<BLSConf
841
858
842
859
#[ context( "Rolling back BLS" ) ]
843
860
pub ( 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
+
844
865
// Sort in descending order as that's the order they're shown on the boot screen
845
866
// After this:
846
867
// all_configs[0] -> booted depl
847
868
// 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 ) ?;
849
870
850
871
// Update the indicies so that they're swapped
851
872
for ( idx, cfg) in all_configs. iter_mut ( ) . enumerate ( ) {
0 commit comments