Skip to content

Commit 27925b4

Browse files
committed
refactor: reduce stop helper args for clippy
1 parent a3e806f commit 27925b4

1 file changed

Lines changed: 25 additions & 16 deletions

File tree

src-tauri/src/main.rs

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2417,32 +2417,37 @@ fn log_status(label: &str, pid: u32, status: &io::Result<ExitStatus>) {
24172417
}
24182418
}
24192419

2420+
struct StopCommandConfig<'a> {
2421+
max_followup: Duration,
2422+
label_graceful: &'a str,
2423+
label_force: &'a str,
2424+
subject: &'a str,
2425+
}
2426+
24202427
fn stop_child_process_impl(
24212428
child: &mut Child,
24222429
timeout: Duration,
24232430
graceful_cmd: impl FnOnce(&str) -> Command,
24242431
force_cmd: impl FnOnce(&str) -> Command,
2425-
max_followup: Duration,
2426-
label_graceful: &str,
2427-
label_force: &str,
2428-
subject: &str,
2432+
config: StopCommandConfig<'_>,
24292433
) -> bool {
24302434
let pid = child.id();
24312435
let pid_arg = pid.to_string();
24322436

24332437
let graceful_status = graceful_cmd(pid_arg.as_str()).status();
2434-
log_status(label_graceful, pid, &graceful_status);
2438+
log_status(config.label_graceful, pid, &graceful_status);
24352439

24362440
if wait_for_child_exit(child, timeout) {
24372441
return true;
24382442
}
24392443

24402444
let force_status = force_cmd(pid_arg.as_str()).status();
2441-
log_status(label_force, pid, &force_status);
2445+
log_status(config.label_force, pid, &force_status);
24422446

2443-
let followup_wait = derive_force_stop_wait(timeout, max_followup);
2447+
let followup_wait = derive_force_stop_wait(timeout, config.max_followup);
24442448
append_desktop_log(&format!(
2445-
"{subject} graceful stop timed out, force-kill issued: pid={pid}, graceful={graceful_status:?}, force={force_status:?}, followup_wait_ms={}",
2449+
"{} graceful stop timed out, force-kill issued: pid={pid}, graceful={graceful_status:?}, force={force_status:?}, followup_wait_ms={}",
2450+
config.subject,
24462451
followup_wait.as_millis(),
24472452
));
24482453
wait_for_child_exit(child, followup_wait)
@@ -2461,10 +2466,12 @@ fn stop_child_process_gracefully(child: &mut Child, timeout: Duration) -> bool {
24612466
timeout,
24622467
|pid_arg| build_stop_command("taskkill", &["/pid", pid_arg, "/t"]),
24632468
|pid_arg| build_stop_command("taskkill", &["/pid", pid_arg, "/t", "/f"]),
2464-
Duration::from_millis(FORCE_STOP_WAIT_MAX_WINDOWS_MS),
2465-
"taskkill graceful stop",
2466-
"taskkill force stop",
2467-
"child",
2469+
StopCommandConfig {
2470+
max_followup: Duration::from_millis(FORCE_STOP_WAIT_MAX_WINDOWS_MS),
2471+
label_graceful: "taskkill graceful stop",
2472+
label_force: "taskkill force stop",
2473+
subject: "child",
2474+
},
24682475
)
24692476
}
24702477

@@ -2475,10 +2482,12 @@ fn stop_child_process_gracefully(child: &mut Child, timeout: Duration) -> bool {
24752482
timeout,
24762483
|pid_arg| build_stop_command("kill", &["-TERM", pid_arg]),
24772484
|pid_arg| build_stop_command("kill", &["-KILL", pid_arg]),
2478-
Duration::from_millis(FORCE_STOP_WAIT_MAX_NON_WINDOWS_MS),
2479-
"kill -TERM",
2480-
"kill -KILL",
2481-
"child",
2485+
StopCommandConfig {
2486+
max_followup: Duration::from_millis(FORCE_STOP_WAIT_MAX_NON_WINDOWS_MS),
2487+
label_graceful: "kill -TERM",
2488+
label_force: "kill -KILL",
2489+
subject: "child",
2490+
},
24822491
)
24832492
}
24842493

0 commit comments

Comments
 (0)