Skip to main content

Mountain/IPC/WindServiceHandlers/Git/
HandleCancel.rs

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