11#[ cfg( any( target_arch = "x86_64" , target_arch = "powerpc64" ) ) ]
22use crate :: bios;
3+ use crate :: component;
34use crate :: component:: { Component , ValidationResult } ;
45use crate :: coreos;
56#[ cfg( any( target_arch = "x86_64" , target_arch = "aarch64" ) ) ]
67use crate :: efi;
78use crate :: model:: { ComponentStatus , ComponentUpdatable , ContentMetadata , SavedState , Status } ;
89use crate :: util;
9- use crate :: { component, ipc} ;
1010use anyhow:: { anyhow, Context , Result } ;
1111use serde:: { Deserialize , Serialize } ;
1212use std:: borrow:: Cow ;
1313use std:: collections:: BTreeMap ;
1414use std:: path:: Path ;
1515
16- /// A message sent from client to server
17- #[ derive( Debug , Serialize , Deserialize ) ]
18- pub ( crate ) enum ClientRequest {
19- /// Update a component
20- Update { component : String } ,
21- /// Update a component via adoption
22- AdoptAndUpdate { component : String } ,
23- /// Validate a component
24- Validate { component : String } ,
25- /// Print the current state
26- Status ,
27- }
28-
2916pub ( crate ) enum ConfigMode {
3017 None ,
3118 Static ,
@@ -408,8 +395,8 @@ pub(crate) fn print_status(status: &Status) -> Result<()> {
408395 Ok ( ( ) )
409396}
410397
411- pub ( crate ) fn client_run_update ( c : & mut ipc :: ClientToDaemonConnection ) -> Result < ( ) > {
412- let status: Status = c . send ( & ClientRequest :: Status ) ?;
398+ pub ( crate ) fn client_run_update ( ) -> Result < ( ) > {
399+ let status: Status = status ( ) ?;
413400 if status. components . is_empty ( ) && status. adoptable . is_empty ( ) {
414401 println ! ( "No components installed." ) ;
415402 return Ok ( ( ) ) ;
@@ -420,9 +407,7 @@ pub(crate) fn client_run_update(c: &mut ipc::ClientToDaemonConnection) -> Result
420407 ComponentUpdatable :: Upgradable => { }
421408 _ => continue ,
422409 } ;
423- match c. send ( & ClientRequest :: Update {
424- component : name. to_string ( ) ,
425- } ) ? {
410+ match update ( name) ? {
426411 ComponentUpdateResult :: AtLatestVersion => {
427412 // Shouldn't happen unless we raced with another client
428413 eprintln ! (
@@ -450,9 +435,7 @@ pub(crate) fn client_run_update(c: &mut ipc::ClientToDaemonConnection) -> Result
450435 }
451436 for ( name, adoptable) in status. adoptable . iter ( ) {
452437 if adoptable. confident {
453- let r: ContentMetadata = c. send ( & ClientRequest :: AdoptAndUpdate {
454- component : name. to_string ( ) ,
455- } ) ?;
438+ let r: ContentMetadata = adopt_and_update ( name) ?;
456439 println ! ( "Adopted and updated: {}: {}" , name, r. version) ;
457440 updated = true ;
458441 } else {
@@ -465,32 +448,28 @@ pub(crate) fn client_run_update(c: &mut ipc::ClientToDaemonConnection) -> Result
465448 Ok ( ( ) )
466449}
467450
468- pub ( crate ) fn client_run_adopt_and_update ( c : & mut ipc :: ClientToDaemonConnection ) -> Result < ( ) > {
469- let status: Status = c . send ( & ClientRequest :: Status ) ?;
451+ pub ( crate ) fn client_run_adopt_and_update ( ) -> Result < ( ) > {
452+ let status: Status = status ( ) ?;
470453 if status. adoptable . is_empty ( ) {
471454 println ! ( "No components are adoptable." ) ;
472455 } else {
473456 for ( name, _) in status. adoptable . iter ( ) {
474- let r: ContentMetadata = c. send ( & ClientRequest :: AdoptAndUpdate {
475- component : name. to_string ( ) ,
476- } ) ?;
457+ let r: ContentMetadata = adopt_and_update ( name) ?;
477458 println ! ( "Adopted and updated: {}: {}" , name, r. version) ;
478459 }
479460 }
480461 Ok ( ( ) )
481462}
482463
483- pub ( crate ) fn client_run_validate ( c : & mut ipc :: ClientToDaemonConnection ) -> Result < ( ) > {
484- let status: Status = c . send ( & ClientRequest :: Status ) ?;
464+ pub ( crate ) fn client_run_validate ( ) -> Result < ( ) > {
465+ let status: Status = status ( ) ?;
485466 if status. components . is_empty ( ) {
486467 println ! ( "No components installed." ) ;
487468 return Ok ( ( ) ) ;
488469 }
489470 let mut caught_validation_error = false ;
490471 for ( name, _) in status. components . iter ( ) {
491- match c. send ( & ClientRequest :: Validate {
492- component : name. to_string ( ) ,
493- } ) ? {
472+ match validate ( name) ? {
494473 ValidationResult :: Valid => {
495474 println ! ( "Validated: {}" , name) ;
496475 }
0 commit comments