diff options
author | Matthias Beyer <matthias.beyer@atos.net> | 2021-01-25 13:49:42 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2021-01-25 14:07:53 +0100 |
commit | 645833f747db227a28cc7bab2ad16d6cafa19843 (patch) | |
tree | b1e49bfe1385418387ebe4a8cc233395e28a3bdf /src/source | |
parent | bbbd5944bfdc9640179dc172ec0dbe4e59b85c97 (diff) |
Reimplement hash verification using streaming
This patch re-implements hashing using streams and buffered readers instead of
reading a full file to RAM before hashing it.
Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
Diffstat (limited to 'src/source')
-rw-r--r-- | src/source/mod.rs | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/src/source/mod.rs b/src/source/mod.rs index b356c31..1c97a87 100644 --- a/src/source/mod.rs +++ b/src/source/mod.rs @@ -97,23 +97,24 @@ impl SourceEntry { Ok(()) } - pub fn verify_hash(&self) -> Result<()> { - use std::io::Read; - + pub async fn verify_hash(&self) -> Result<()> { let p = self.source_file_path(); - trace!("Reading to buffer: {}", p.display()); + trace!("Verifying : {}", p.display()); let path = p.clone(); - let mut buf = vec![]; - std::fs::OpenOptions::new() - .create(false) - .create_new(false) - .read(true) - .open(path)? - .read_to_end(&mut buf)?; - - trace!("Reading to buffer finished: {}", p.display()); - self.package_source.hash().matches_hash_of(&buf) + let reader = tokio::task::spawn_blocking(move || { + std::fs::OpenOptions::new() + .create(false) + .create_new(false) + .read(true) + .open(path) + .map(std::io::BufReader::new) + }) + .await??; + + self.package_source + .hash() + .matches_hash_of(reader) } pub async fn create(&self) -> Result<tokio::fs::File> { |