(file: &PathBuf, compression: Option<Compression>)
| 34 | } |
| 35 | |
| 36 | fn handle_file(file: &PathBuf, compression: Option<Compression>) -> io::Result<bool> { |
| 37 | let est = Compresstimator::with_block_size(8192); |
| 38 | let meta = std::fs::metadata(&file)?; |
| 39 | let handle = std::fs::OpenOptions::new() |
| 40 | .access_mode(FILE_WRITE_ATTRIBUTES | FILE_READ_DATA) |
| 41 | .open(&file)?; |
| 42 | |
| 43 | handle.try_lock_exclusive()?; |
| 44 | |
| 45 | let ret = match compression { |
| 46 | Some(compression) => match est.compresstimate(&handle, meta.len()) { |
| 47 | Ok(ratio) if ratio < 0.95 => compact::compress_file_handle(&handle, compression), |
| 48 | Ok(_) => Ok(false), |
| 49 | Err(e) => Err(e), |
| 50 | }, |
| 51 | None => compact::uncompress_file_handle(&handle).map(|_| true), |
| 52 | }; |
| 53 | |
| 54 | let _ = filetime::set_file_handle_times( |
| 55 | &handle, |
| 56 | Some(FileTime::from_last_access_time(&meta)), |
| 57 | Some(FileTime::from_last_modification_time(&meta)), |
| 58 | ); |
| 59 | |
| 60 | handle.unlock()?; |
| 61 | |
| 62 | ret |
| 63 | } |
| 64 | |
| 65 | impl Background for BackgroundCompactor { |
| 66 | type Output = (); |
no test coverage detected