diff options
Diffstat (limited to 'crates/daemon/src/api/control.rs')
| -rw-r--r-- | crates/daemon/src/api/control.rs | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/crates/daemon/src/api/control.rs b/crates/daemon/src/api/control.rs index ff19f593..8277f434 100644 --- a/crates/daemon/src/api/control.rs +++ b/crates/daemon/src/api/control.rs @@ -6,7 +6,7 @@ use tokio::time::{self, MissedTickBehavior}; use tonic::{Request, Response, Status}; use tracing::{Level, instrument}; -use turtle::generated::{ +use turtle_api::generated::{ DAEMON_PROTOCOL_VERSION, control::{ ForceSyncReply, ForceSyncRequest, PathsReply, PathsRequest, StatusReply, StatusRequest, @@ -91,9 +91,36 @@ impl Control for ControlService { &self, _request: Request<ForceSyncRequest>, ) -> Result<Response<ForceSyncReply>, Status> { - let reply = ForceSyncReply { accepted: true }; - self.handle.emit(DaemonEvent::ForceSync); + let event = self + .handle + .wait_for(|e| { + matches!( + e, + DaemonEvent::SyncFailed { .. } | DaemonEvent::SyncCompleted { .. } + ) + }) + .await + .map_err(|e| { + Status::internal(format!("failed to wait for sync response event: {e:?}")) + })?; + + let reply = match event { + DaemonEvent::SyncCompleted { + uploaded, + downloaded, + } => ForceSyncReply { + error: None, + uploaded: uploaded as u32, + downloaded: downloaded as u32, + }, + DaemonEvent::SyncFailed { error } => ForceSyncReply { + error: Some(error), + uploaded: 0, + downloaded: 0, + }, + _ => unreachable!(), + }; Ok(Response::new(reply)) } |
