@@ -6,16 +6,10 @@ use anyhow::{bail, Context, Result};
66use bootc_blockdev:: PartitionTable ;
77use fn_error_context:: context;
88
9- static PARENT_DEVICES : OnceLock < Vec < String > > = OnceLock :: new ( ) ;
10-
11- // Initialize once
12- pub fn init_parent_devices ( strings : Vec < String > ) {
13- PARENT_DEVICES . set ( strings) . expect ( "Already initialized" ) ;
14- }
15-
16- // Read many times (lock-free)
17- pub fn get_parent_devices ( ) -> & ' static [ String ] {
18- PARENT_DEVICES . get ( ) . expect ( "Not initialized" )
9+ /// Get parent devices
10+ pub fn get_or_init_parent_devices ( devices : Option < Vec < String > > ) -> & ' static [ String ] {
11+ static PARENT_DEVICES : OnceLock < Vec < String > > = OnceLock :: new ( ) ;
12+ PARENT_DEVICES . get_or_init ( || devices. unwrap ( ) )
1913}
2014
2115#[ context( "get parent devices from mount point boot" ) ]
@@ -68,7 +62,7 @@ pub fn get_esp_partition(device: &str) -> Result<Option<String>> {
6862#[ allow( dead_code) ]
6963pub fn find_colocated_esps ( ) -> Result < Vec < String > > {
7064 // first, get the parent device
71- let devices = get_parent_devices ( ) ;
65+ let devices = get_or_init_parent_devices ( None ) ;
7266
7367 // now, look for all ESPs on those devices
7468 let mut esps = Vec :: new ( ) ;
@@ -99,7 +93,7 @@ pub fn get_bios_boot_partition(device: &str) -> Result<Option<String>> {
9993#[ allow( dead_code) ]
10094pub fn find_colocated_bios_boot ( ) -> Result < Vec < String > > {
10195 // first, get the parent device
102- let devices = get_parent_devices ( ) ;
96+ let devices = get_or_init_parent_devices ( None ) ;
10397
10498 // now, look for all bios_boot parts on those devices
10599 let mut bios_boots = Vec :: new ( ) ;
0 commit comments