MCPcopy Create free account
hub / github.com/Freaky/Compactor / scan_loop

Method scan_loop

src/backend.rs:74–133  ·  view source on GitHub ↗
(&mut self, path: PathBuf)

Source from the content-addressed store, hash-verified

72 }
73
74 fn scan_loop(&mut self, path: PathBuf) {
75 let excludes = config().read().unwrap().current().globset().expect("globs");
76
77 let scanner = FolderScan::new(path, excludes);
78 let task = BackgroundHandle::spawn(scanner);
79 let start = Instant::now();
80
81 self.gui.status("Scanning", None);
82 loop {
83 let msg = self.msg.recv_timeout(Duration::from_millis(25));
84
85 match msg {
86 Ok(GuiRequest::Pause) => {
87 task.pause();
88 self.gui.status("Paused", Some(0.5));
89 self.gui.paused();
90 }
91 Ok(GuiRequest::Resume) => {
92 task.resume();
93 self.gui.status("Scanning", None);
94 self.gui.resumed();
95 }
96 Ok(GuiRequest::Stop) | Err(RecvTimeoutError::Disconnected) => {
97 task.cancel();
98 }
99 Ok(msg) => {
100 eprintln!("Ignored message: {:?}", msg);
101 }
102 Err(RecvTimeoutError::Timeout) => (),
103 }
104
105 match task.wait_timeout(Duration::from_millis(25)) {
106 Some(Ok(info)) => {
107 self.gui
108 .status(format!("Scanned in {:.2?}", start.elapsed()), Some(1.0));
109 self.gui.summary(info.summary());
110 self.gui.scanned();
111 self.info = Some(info);
112 break;
113 }
114 Some(Err(info)) => {
115 self.gui.status(
116 format!("Scan stopped after {:.2?}", start.elapsed()),
117 Some(0.5),
118 );
119 self.gui.summary(info.summary());
120 self.gui.stopped();
121 self.info = Some(info);
122 break;
123 }
124 None => {
125 if let Some(status) = task.status() {
126 self.gui
127 .status(format!("Scanning: {}", status.0.display()), None);
128 self.gui.summary(status.1);
129 }
130 }
131 }

Callers 1

runMethod · 0.80

Calls 13

configFunction · 0.85
globsetMethod · 0.80
currentMethod · 0.80
pauseMethod · 0.80
pausedMethod · 0.80
resumeMethod · 0.80
resumedMethod · 0.80
cancelMethod · 0.80
wait_timeoutMethod · 0.80
scannedMethod · 0.80
stoppedMethod · 0.80
statusMethod · 0.45

Tested by

no test coverage detected