1use super::*;
4use std::path::PathBuf;
5
6pub struct StopFileHandler {
9 stop_file: PathBuf,
10}
11
12impl StopFileHandler {
13 pub fn new() -> Self {
14 let stop_file = PathBuf::from("STOP");
15 if stop_file.exists() {
16 println!("Removing existing STOP file ...");
17 let _ = std::fs::remove_file(&stop_file);
18 }
19 Self {
20 stop_file: PathBuf::from("STOP"),
21 }
22 }
23
24 fn is_interrupted(&self) -> bool {
25 self.stop_file.exists()
26 }
27
28 pub fn handle_user_interruption(&self) -> Result<()> {
30 if self.is_interrupted() {
31 bail!("found STOP file, stopping now ...");
32 } else {
33 Ok(())
34 }
35 }
36}
37