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

Method compress_loop

src/backend.rs:136–315  ·  view source on GitHub ↗

Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn.

(&mut self)

Source from the content-addressed store, hash-verified

134
135 // Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn.
136 fn compress_loop(&mut self) {
137 let (send_file, send_file_rx) = bounded::<(PathBuf, u64)>(1);
138 let (recv_result_tx, recv_result) = bounded::<(PathBuf, io::Result<bool>)>(1);
139
140 let compression = Some(config().read().unwrap().current().compression);
141 let compactor = BackgroundCompactor::new(compression, send_file_rx, recv_result_tx);
142 let task = BackgroundHandle::spawn(compactor);
143 let start = Instant::now();
144
145 let mut folder = self.info.take().expect("fileinfo");
146 let total = folder.len(FileKind::Compressible);
147 let mut done = 0;
148
149 let mut last_update = Instant::now();
150 let mut last_write = Instant::now();
151 let mut paused = false;
152 let mut stopped = false;
153
154 let old_size = folder.physical_size;
155 let compressible_size = folder.summary().compressible.physical_size;
156
157 let incompressible = pathdb();
158 let mut incompressible = incompressible.write().unwrap();
159 let _ = incompressible.load();
160
161 self.gui.compacting();
162
163 self.gui.status("Compacting".to_string(), Some(0.0));
164 loop {
165 while paused && !stopped {
166 self.gui
167 .status("Paused".to_string(), Some(done as f32 / total as f32));
168
169 self.gui.summary(folder.summary());
170
171 match self.msg.recv() {
172 Ok(GuiRequest::Pause) => {
173 paused = true;
174 }
175 Ok(GuiRequest::Resume) => {
176 self.gui
177 .status("Compacting".to_string(), Some(done as f32 / total as f32));
178 self.gui.resumed();
179 paused = false;
180 last_update = Instant::now();
181 }
182 Ok(GuiRequest::Stop) => {
183 stopped = true;
184 break;
185 }
186 Ok(_) => (),
187 Err(_) => {
188 stopped = true;
189 break;
190 }
191 }
192 }
193

Callers 1

runMethod · 0.80

Calls 15

configFunction · 0.85
pathdbFunction · 0.85
currentMethod · 0.80
lenMethod · 0.80
loadMethod · 0.80
compactingMethod · 0.80
resumedMethod · 0.80
popMethod · 0.80
sendMethod · 0.80
insertMethod · 0.80
pushMethod · 0.80
pausedMethod · 0.80

Tested by

no test coverage detected