@@ -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 } ;
@@ -752,8 +753,11 @@ pub(crate) fn rollback_composefs_uki() -> Result<()> {
752
753
let user_cfg_path = PathBuf :: from ( "/sysroot/boot/grub2" ) ;
753
754
754
755
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" ) ?;
755
759
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" ) ?;
757
761
758
762
// TODO(Johan-Liebert): Currently assuming there are only two deployments
759
763
assert ! ( menuentries. len( ) == 2 ) ;
@@ -800,17 +804,25 @@ pub(crate) fn rollback_composefs_uki() -> Result<()> {
800
804
}
801
805
802
806
// 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}" ) ) ?;
805
814
file. read_to_string ( str) ?;
806
815
parse_grub_menuentry_file ( str)
807
816
}
808
817
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 > > {
811
823
let mut all_configs = vec ! [ ] ;
812
824
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}" ) ) ? {
814
826
let entry = entry?;
815
827
816
828
let file_name = entry. file_name ( ) ;
@@ -823,8 +835,13 @@ pub(crate) fn get_sorted_bls_boot_entries(ascending: bool) -> Result<Vec<BLSConf
823
835
continue ;
824
836
}
825
837
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) ) ?;
828
845
829
846
let config = parse_bls_config ( & contents) . context ( "Parsing bls config" ) ?;
830
847
@@ -838,11 +855,15 @@ pub(crate) fn get_sorted_bls_boot_entries(ascending: bool) -> Result<Vec<BLSConf
838
855
839
856
#[ context( "Rolling back BLS" ) ]
840
857
pub ( 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
+
841
862
// Sort in descending order as that's the order they're shown on the boot screen
842
863
// After this:
843
864
// all_configs[0] -> booted depl
844
865
// 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 ) ?;
846
867
847
868
// Update the indicies so that they're swapped
848
869
for ( idx, cfg) in all_configs. iter_mut ( ) . enumerate ( ) {
0 commit comments