summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-04-23 11:15:16 +0300
committerLars Wirzenius <liw@liw.fi>2021-04-23 11:15:16 +0300
commit35f3c2a309b7a39a079dc8223d3cc8da3f6704f7 (patch)
treea1ed71ba0fed7d99fe0c728c43aec24554957da0
parent7ea9c6459d621a96fa496a2fe2ae4ecc941a33ce (diff)
downloadsummain-rs-35f3c2a309b7a39a079dc8223d3cc8da3f6704f7.tar.gz
spawn task just for hashing
-rw-r--r--src/lib.rs5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 00c64cf..cc1a751 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -63,7 +63,8 @@ impl ManifestEntry {
pub async fn new(path: &Path) -> std::io::Result<Self> {
let m = symlink_metadata(path)?;
let hash = if m.is_file() {
- Some(file_checksum(path)?)
+ let path = path.to_path_buf();
+ Some(tokio::task::spawn_blocking(move || file_checksum(path)).await??)
} else {
None
};
@@ -85,7 +86,7 @@ impl ManifestEntry {
}
}
-fn file_checksum(path: &Path) -> std::io::Result<String> {
+fn file_checksum(path: PathBuf) -> std::io::Result<String> {
let mut hasher = Sha256::new();
let file = File::open(path)?;