Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn.
(&mut self)
| 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 |