@@ -216,16 +216,16 @@ fn ensure_writable_boot() -> Result<()> {
216
216
}
217
217
218
218
/// 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 ( ) ;
221
221
let component = component:: new_from_name ( name) ?;
222
222
let inst = if let Some ( inst) = state. installed . get ( name) {
223
223
inst. clone ( )
224
224
} else {
225
225
anyhow:: bail!( "Component {} is not installed" , name) ;
226
226
} ;
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) ?;
229
229
let update = match update. as_ref ( ) {
230
230
Some ( p) if inst. meta . can_upgrade_to ( p) => p,
231
231
_ => return Ok ( ComponentUpdateResult :: AtLatestVersion ) ,
@@ -236,6 +236,7 @@ pub(crate) fn update(name: &str) -> Result<ComponentUpdateResult> {
236
236
let mut pending_container = state. pending . take ( ) . unwrap_or_default ( ) ;
237
237
let interrupted = pending_container. get ( component. name ( ) ) . cloned ( ) ;
238
238
pending_container. insert ( component. name ( ) . into ( ) , update. clone ( ) ) ;
239
+ let sysroot = sysroot. try_clone ( ) ?;
239
240
let mut state_guard =
240
241
SavedState :: acquire_write_lock ( sysroot) . context ( "Failed to acquire write lock" ) ?;
241
242
state_guard
@@ -257,19 +258,20 @@ pub(crate) fn update(name: &str) -> Result<ComponentUpdateResult> {
257
258
}
258
259
259
260
/// 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 ( ) ;
263
264
let component = component:: new_from_name ( name) ?;
264
265
if state. installed . contains_key ( name) {
265
266
anyhow:: bail!( "Component {} is already installed" , name) ;
266
267
} ;
267
268
268
269
ensure_writable_boot ( ) ?;
269
270
270
- let Some ( update) = component. query_update ( & sysroot) ? else {
271
+ let Some ( update) = component. query_update ( sysroot) ? else {
271
272
anyhow:: bail!( "Component {} has no available update" , name) ;
272
273
} ;
274
+ let sysroot = sysroot. try_clone ( ) ?;
273
275
let mut state_guard =
274
276
SavedState :: acquire_write_lock ( sysroot) . context ( "Failed to acquire write lock" ) ?;
275
277
@@ -412,6 +414,7 @@ pub(crate) fn print_status(status: &Status) -> Result<()> {
412
414
pub struct RootContext {
413
415
pub sysroot : openat:: Dir ,
414
416
pub path : Utf8PathBuf ,
417
+ #[ allow( dead_code) ]
415
418
pub devices : Vec < String >
416
419
}
417
420
@@ -439,6 +442,7 @@ fn prep_before_update() -> Result<RootContext> {
439
442
440
443
pub ( crate ) fn client_run_update ( ) -> Result < ( ) > {
441
444
crate :: try_fail_point!( "update" ) ;
445
+ let rootcxt = prep_before_update ( ) ?;
442
446
let status: Status = status ( ) ?;
443
447
if status. components . is_empty ( ) && status. adoptable . is_empty ( ) {
444
448
println ! ( "No components installed." ) ;
@@ -450,7 +454,7 @@ pub(crate) fn client_run_update() -> Result<()> {
450
454
ComponentUpdatable :: Upgradable => { }
451
455
_ => continue ,
452
456
} ;
453
- match update ( name) ? {
457
+ match update ( name, & rootcxt ) ? {
454
458
ComponentUpdateResult :: AtLatestVersion => {
455
459
// Shouldn't happen unless we raced with another client
456
460
eprintln ! (
@@ -478,7 +482,7 @@ pub(crate) fn client_run_update() -> Result<()> {
478
482
}
479
483
for ( name, adoptable) in status. adoptable . iter ( ) {
480
484
if adoptable. confident {
481
- let r: ContentMetadata = adopt_and_update ( name) ?;
485
+ let r: ContentMetadata = adopt_and_update ( name, & rootcxt ) ?;
482
486
println ! ( "Adopted and updated: {}: {}" , name, r. version) ;
483
487
updated = true ;
484
488
} else {
@@ -492,12 +496,13 @@ pub(crate) fn client_run_update() -> Result<()> {
492
496
}
493
497
494
498
pub ( crate ) fn client_run_adopt_and_update ( ) -> Result < ( ) > {
499
+ let rootcxt = prep_before_update ( ) ?;
495
500
let status: Status = status ( ) ?;
496
501
if status. adoptable . is_empty ( ) {
497
502
println ! ( "No components are adoptable." ) ;
498
503
} else {
499
504
for ( name, _) in status. adoptable . iter ( ) {
500
- let r: ContentMetadata = adopt_and_update ( name) ?;
505
+ let r: ContentMetadata = adopt_and_update ( name, & rootcxt ) ?;
501
506
println ! ( "Adopted and updated: {}: {}" , name, r. version) ;
502
507
}
503
508
}
0 commit comments