Skip to main content

Mountain/IPC/WindServiceHandlers/Git/
HandleCancel.rs

1
2//! `localGit:cancel(operationId)` - SIGTERM (Unix) or
3//! `taskkill /T /F` (Windows) the pid stashed for
4//! `OperationId`. Silent no-op when the id is unknown so
5//! late-arriving cancels for already-finished operations
6//! don't spam errors.
7
8use serde_json::Value;
9
10use crate::{IPC::WindServiceHandlers::Git::Shared::TakePid::Fn as TakePid, dev_log};
11
12pub async fn Fn(Arguments:Vec<Value>) -> Result<Value, String> {
13	let OperationId = Arguments.first().and_then(Value::as_str).unwrap_or("").to_string();
14
15	if let Some(Pid) = TakePid(&OperationId) {
16		dev_log!("git", "[Git] cancel op={} pid={}", OperationId, Pid);
17
18		#[cfg(unix)]
19		{
20			let _ = std::process::Command::new("kill").args(["-TERM", &Pid.to_string()]).output();
21		}
22
23		#[cfg(windows)]
24		{
25			let _ = std::process::Command::new("taskkill")
26				.args(["/PID", &Pid.to_string(), "/T", "/F"])
27				.output();
28		}
29	} else {
30		dev_log!("git", "[Git] cancel op={} pid=<unknown>", OperationId);
31	}
32
33	Ok(Value::Null)
34}