summaryrefslogtreecommitdiffstats
path: root/src/source
diff options
context:
space:
mode:
Diffstat (limited to 'src/source')
-rw-r--r--src/source/mod.rs30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/source/mod.rs b/src/source/mod.rs
index 75a1609..295d7a9 100644
--- a/src/source/mod.rs
+++ b/src/source/mod.rs
@@ -91,29 +91,29 @@ impl SourceEntry {
}
pub async fn verify_hash(&self) -> Result<()> {
+
let p = self.source_file_path();
- trace!("Reading: {}", p.display());
+ trace!("Reading to buffer: {}", 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 buf = tokio::task::spawn_blocking(move || {
+ use std::io::Read;
- tokio::task::spawn_blocking(move || {
+ let mut buf = vec![];
std::fs::OpenOptions::new()
.create(false)
.create_new(false)
.read(true)
- .open(&p)
- .map_err(Error::from)
- .map(std::io::BufReader::new)
- .and_then(|reader| {
- source_hash.matches_hash_of(reader)
- })
+ .open(path)?
+ .read_to_end(&mut buf)
+ .map(|_| buf)
})
- .await?
+ .await??;
+
+ trace!("Reading to buffer finished: {}", p.display());
+ self.package_source
+ .hash()
+ .matches_hash_of(&buf)
}
pub async fn create(&self) -> Result<tokio::fs::File> {