(process_name: &str)
| 328 | } |
| 329 | |
| 330 | fn close_cursor_process(process_name: &str) { |
| 331 | let mut sys = System::new_all(); |
| 332 | sys.refresh_processes(); |
| 333 | |
| 334 | let processes_to_kill: Vec<_> = sys |
| 335 | .processes() |
| 336 | .values() |
| 337 | .filter(|p| p.name().eq_ignore_ascii_case(process_name)) |
| 338 | .collect(); |
| 339 | |
| 340 | if !processes_to_kill.is_empty() { |
| 341 | println!("{} Found {} running", "[WARNING]".color(YELLOW), process_name); |
| 342 | for p in &processes_to_kill { |
| 343 | println!(" PID: {}, Name: {}, Path: {:?}", p.pid(), p.name(), p.exe()); |
| 344 | } |
| 345 | |
| 346 | println!("{} Attempting to close {}...", "[WARNING]".color(YELLOW), process_name); |
| 347 | for p in processes_to_kill { |
| 348 | if !p.kill() { // kill() sends SIGKILL by default on Unix, TerminateProcess on Windows |
| 349 | println!("{} Failed to send termination signal to {} (PID: {}). Trying to wait...", "[ERROR]".color(RED), process_name, p.pid()); |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | let mut retry_count = 0; |
| 354 | loop { |
| 355 | sys.refresh_processes(); |
| 356 | let still_running: Vec<_> = sys |
| 357 | .processes() |
| 358 | .values() |
| 359 | .filter(|p| p.name().eq_ignore_ascii_case(process_name)) |
| 360 | .collect(); |
| 361 | |
| 362 | if still_running.is_empty() { |
| 363 | break; |
| 364 | } |
| 365 | |
| 366 | retry_count += 1; |
| 367 | if retry_count >= MAX_RETRIES { |
| 368 | println!("{} Unable to close {} after {} attempts", "[ERROR]".color(RED), process_name, MAX_RETRIES); |
| 369 | for p in still_running { |
| 370 | println!(" Still running - PID: {}, Name: {}, Path: {:?}", p.pid(), p.name(), p.exe()); |
| 371 | } |
| 372 | println!("{} Please close the process manually and try again", "[ERROR]".color(RED)); |
| 373 | press_enter_to_exit(1); |
| 374 | } |
| 375 | |
| 376 | println!("{} Waiting for process to close, attempt {}/{}...", "[WARNING]".color(YELLOW), retry_count, MAX_RETRIES); |
| 377 | std::thread::sleep(std::time::Duration::from_secs(WAIT_TIME_SECONDS)); |
| 378 | } |
| 379 | println!("{} {} successfully closed", "[INFO]".color(GREEN), process_name); |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | fn update_storage_file( |
| 384 | storage_file_path: &Path, |
no test coverage detected