@@ -216,16 +216,16 @@ fn ensure_writable_boot() -> Result<()> {
216216}
217217
218218/// daemon implementation of component update
219- pub ( crate ) fn update ( name : & str ) -> Result < ComponentUpdateResult > {
220- let mut state = SavedState :: load_from_disk ( "/" ) ?. unwrap_or_default ( ) ;
219+ pub ( crate ) fn update ( name : & str , rootcxt : & RootContext ) -> Result < ComponentUpdateResult > {
220+ let mut state = SavedState :: load_from_disk ( & rootcxt . path ) ?. unwrap_or_default ( ) ;
221221 let component = component:: new_from_name ( name) ?;
222222 let inst = if let Some ( inst) = state. installed . get ( name) {
223223 inst. clone ( )
224224 } else {
225225 anyhow:: bail!( "Component {} is not installed" , name) ;
226226 } ;
227- let sysroot = openat :: Dir :: open ( "/" ) ? ;
228- let update = component. query_update ( & sysroot) ?;
227+ let sysroot = & rootcxt . sysroot ;
228+ let update = component. query_update ( sysroot) ?;
229229 let update = match update. as_ref ( ) {
230230 Some ( p) if inst. meta . can_upgrade_to ( p) => p,
231231 _ => return Ok ( ComponentUpdateResult :: AtLatestVersion ) ,
@@ -236,6 +236,7 @@ pub(crate) fn update(name: &str) -> Result<ComponentUpdateResult> {
236236 let mut pending_container = state. pending . take ( ) . unwrap_or_default ( ) ;
237237 let interrupted = pending_container. get ( component. name ( ) ) . cloned ( ) ;
238238 pending_container. insert ( component. name ( ) . into ( ) , update. clone ( ) ) ;
239+ let sysroot = sysroot. try_clone ( ) ?;
239240 let mut state_guard =
240241 SavedState :: acquire_write_lock ( sysroot) . context ( "Failed to acquire write lock" ) ?;
241242 state_guard
@@ -257,19 +258,20 @@ pub(crate) fn update(name: &str) -> Result<ComponentUpdateResult> {
257258}
258259
259260/// daemon implementation of component adoption
260- pub ( crate ) fn adopt_and_update ( name : & str ) -> Result < ContentMetadata > {
261- let sysroot = openat :: Dir :: open ( "/" ) ? ;
262- let mut state = SavedState :: load_from_disk ( "/" ) ?. unwrap_or_default ( ) ;
261+ pub ( crate ) fn adopt_and_update ( name : & str , rootcxt : & RootContext ) -> Result < ContentMetadata > {
262+ let sysroot = & rootcxt . sysroot ;
263+ let mut state = SavedState :: load_from_disk ( & rootcxt . path ) ?. unwrap_or_default ( ) ;
263264 let component = component:: new_from_name ( name) ?;
264265 if state. installed . contains_key ( name) {
265266 anyhow:: bail!( "Component {} is already installed" , name) ;
266267 } ;
267268
268269 ensure_writable_boot ( ) ?;
269270
270- let Some ( update) = component. query_update ( & sysroot) ? else {
271+ let Some ( update) = component. query_update ( sysroot) ? else {
271272 anyhow:: bail!( "Component {} has no available update" , name) ;
272273 } ;
274+ let sysroot = sysroot. try_clone ( ) ?;
273275 let mut state_guard =
274276 SavedState :: acquire_write_lock ( sysroot) . context ( "Failed to acquire write lock" ) ?;
275277
@@ -412,6 +414,7 @@ pub(crate) fn print_status(status: &Status) -> Result<()> {
412414pub struct RootContext {
413415 pub sysroot : openat:: Dir ,
414416 pub path : Utf8PathBuf ,
417+ #[ allow( dead_code) ]
415418 pub devices : Vec < String >
416419}
417420
@@ -439,6 +442,7 @@ fn prep_before_update() -> Result<RootContext> {
439442
440443pub ( crate ) fn client_run_update ( ) -> Result < ( ) > {
441444 crate :: try_fail_point!( "update" ) ;
445+ let rootcxt = prep_before_update ( ) ?;
442446 let status: Status = status ( ) ?;
443447 if status. components . is_empty ( ) && status. adoptable . is_empty ( ) {
444448 println ! ( "No components installed." ) ;
@@ -450,7 +454,7 @@ pub(crate) fn client_run_update() -> Result<()> {
450454 ComponentUpdatable :: Upgradable => { }
451455 _ => continue ,
452456 } ;
453- match update ( name) ? {
457+ match update ( name, & rootcxt ) ? {
454458 ComponentUpdateResult :: AtLatestVersion => {
455459 // Shouldn't happen unless we raced with another client
456460 eprintln ! (
@@ -478,7 +482,7 @@ pub(crate) fn client_run_update() -> Result<()> {
478482 }
479483 for ( name, adoptable) in status. adoptable . iter ( ) {
480484 if adoptable. confident {
481- let r: ContentMetadata = adopt_and_update ( name) ?;
485+ let r: ContentMetadata = adopt_and_update ( name, & rootcxt ) ?;
482486 println ! ( "Adopted and updated: {}: {}" , name, r. version) ;
483487 updated = true ;
484488 } else {
@@ -492,12 +496,13 @@ pub(crate) fn client_run_update() -> Result<()> {
492496}
493497
494498pub ( crate ) fn client_run_adopt_and_update ( ) -> Result < ( ) > {
499+ let rootcxt = prep_before_update ( ) ?;
495500 let status: Status = status ( ) ?;
496501 if status. adoptable . is_empty ( ) {
497502 println ! ( "No components are adoptable." ) ;
498503 } else {
499504 for ( name, _) in status. adoptable . iter ( ) {
500- let r: ContentMetadata = adopt_and_update ( name) ?;
505+ let r: ContentMetadata = adopt_and_update ( name, & rootcxt ) ?;
501506 println ! ( "Adopted and updated: {}: {}" , name, r. version) ;
502507 }
503508 }
0 commit comments