Skip to main content

AirLibrary/Client/AirClient/
ApplyUpdate.rs

1//! `AirClient::ApplyUpdate` - applies a previously-downloaded update
2//! package via the Air daemon's `UpdateService`.
3//!
4//! `response.success == true` → `Ok(())`. `response.success == false` →
5//! [`AirError::Internal`] carrying the server-side error string. tonic
6//! transport / status failures surface as [`AirError::Network`].
7
8use tonic::Request;
9
10use crate::{AirError, Client::AirClient::AirClient, Vine::Generated::air::ApplyUpdateRequest, dev_log};
11
12impl AirClient {
13	/// Applies an update package.
14	///
15	/// # Arguments
16	///
17	/// - `request_id` - opaque correlation id.
18	/// - `version` - the version string of the update being applied.
19	/// - `update_path` - filesystem path of the downloaded update bundle.
20	pub async fn ApplyUpdate(&self, request_id:String, version:String, update_path:String) -> Result<(), AirError> {
21		dev_log!("grpc", "[AirClient] Applying update version: {}", version);
22
23		let RequestPayload = ApplyUpdateRequest { request_id, version, update_path };
24
25		let Client = self
26			.Client()
27			.ok_or_else(|| AirError::Network("Air client not initialized".to_string()))?;
28
29		let mut ClientGuard = Client.lock().await;
30
31		match ClientGuard.apply_update(Request::new(RequestPayload)).await {
32			Ok(Response) => {
33				let Response = Response.into_inner();
34
35				if Response.success {
36					dev_log!("grpc", "[AirClient] Update applied successfully");
37
38					Ok(())
39				} else {
40					dev_log!("grpc", "error: [AirClient] Update application failed: {}", Response.error);
41
42					Err(AirError::Internal(Response.error))
43				}
44			},
45
46			Err(Status) => {
47				dev_log!("grpc", "error: [AirClient] Apply update RPC error: {}", Status);
48
49				Err(AirError::Network(format!("Apply update RPC error: {}", Status)))
50			},
51		}
52	}
53}