diff options
author | Matthias Beyer <matthias.beyer@atos.net> | 2021-01-12 10:35:01 +0100 |
---|---|---|
committer | Matthias Beyer <matthias.beyer@atos.net> | 2021-01-12 10:35:01 +0100 |
commit | c3fc1281142ec10414197a31070cc45930a859e3 (patch) | |
tree | 44aafa91fc713310317582344bc0e40f5309fe91 /src/source | |
parent | 18b256e040881ac674463913b2a7e290125ea738 (diff) |
Move hashing itself into blocking task
This patch, as a followup to 18b256e040881ac674463913b2a7e290125ea738
("Reimplement hash verification") moves the hashing itself into the blocking
closure, so that we get maximum parallelism here.
Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
Diffstat (limited to 'src/source')
-rw-r--r-- | src/source/mod.rs | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/source/mod.rs b/src/source/mod.rs index 734b89e..ebc60dd 100644 --- a/src/source/mod.rs +++ b/src/source/mod.rs @@ -81,25 +81,29 @@ impl SourceEntry { } pub async fn verify_hash(&self) -> Result<()> { - let p = self.source_file_path(); - trace!("Reading to buffer: {}", p.display()); + trace!("Reading: {}", p.display()); + + // we can clone() here, because the object itself is just a representation of "what hash + // type do we use here", which is rather cheap to clone (because it is + // crate::package::SourceHash, that is not more than an enum + String). + // + // We need to clone to move into the closure below. + let source_hash = self.package_source.hash().clone(); - let path = p.clone(); - let reader = tokio::task::spawn_blocking(move || { + tokio::task::spawn_blocking(move || { std::fs::OpenOptions::new() .create(false) .create_new(false) .read(true) - .open(path) + .open(&p) + .map_err(Error::from) .map(std::io::BufReader::new) + .and_then(|reader| { + source_hash.matches_hash_of(reader) + }) }) - .await??; - - trace!("Reading to buffer finished: {}", p.display()); - self.package_source - .hash() - .matches_hash_of(reader) + .await? } pub async fn create(&self) -> Result<tokio::fs::File> { |