From 7cd782271e7020bd630fe676e4b968c272d87dfd Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Mon, 16 Jan 2023 14:26:08 +1100
Subject: [PATCH] Bump async_zip from 0.0.9 to 0.0.10 (#709)

* Bump async_zip from 0.0.9 to 0.0.10

Bumps [async_zip](https://github.com/Majored/rs-async-zip) from 0.0.9 to 0.0.10.
- [Release notes](https://github.com/Majored/rs-async-zip/releases)
- [Commits](https://github.com/Majored/rs-async-zip/compare/v0.0.9...v0.0.10)

---
updated-dependencies:
- dependency-name: async_zip
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

* Fix usage of `async_zip::read::stream` APIs


Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jiahao XU <Jiahao_XU@outlook.com>
---
 Cargo.lock                                    | 144 +-----------------
 crates/binstalk-downloader/Cargo.toml         |   2 +-
 .../src/download/async_extracter.rs           |   6 +-
 .../src/download/zip_extraction.rs            |  29 ++--
 4 files changed, 29 insertions(+), 152 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index 151d65da..c72de44e 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -52,15 +52,6 @@ dependencies = [
  "alloc-no-stdlib",
 ]
 
-[[package]]
-name = "android_system_properties"
-version = "0.1.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
-dependencies = [
- "libc",
-]
-
 [[package]]
 name = "async-compression"
 version = "0.3.15"
@@ -90,25 +81,15 @@ dependencies = [
  "syn",
 ]
 
-[[package]]
-name = "async_io_utilities"
-version = "0.1.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9b20cffc5590f4bf33f05f97a3ea587feba9c50d20325b401daa096b92ff7da0"
-dependencies = [
- "tokio",
-]
-
 [[package]]
 name = "async_zip"
-version = "0.0.9"
+version = "0.0.10"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6a36d43bdefc7215b2b3a97edd03b1553b7969ad76551025eedd3b913c645f6e"
+checksum = "b5282f208287c58b7df1f7965531a49192eb4a22558fa1421d26d1a7c6118613"
 dependencies = [
  "async-compression",
- "async_io_utilities",
- "chrono",
  "crc32fast",
+ "pin-project",
  "thiserror",
  "tokio",
 ]
@@ -411,14 +392,9 @@ version = "0.4.23"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f"
 dependencies = [
- "iana-time-zone",
- "js-sys",
  "num-integer",
  "num-traits",
  "serde",
- "time",
- "wasm-bindgen",
- "winapi",
 ]
 
 [[package]]
@@ -467,16 +443,6 @@ dependencies = [
  "cc",
 ]
 
-[[package]]
-name = "codespan-reporting"
-version = "0.11.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e"
-dependencies = [
- "termcolor",
- "unicode-width",
-]
-
 [[package]]
 name = "command-group"
 version = "2.0.1"
@@ -554,50 +520,6 @@ dependencies = [
  "typenum",
 ]
 
-[[package]]
-name = "cxx"
-version = "1.0.86"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "51d1075c37807dcf850c379432f0df05ba52cc30f279c5cfc43cc221ce7f8579"
-dependencies = [
- "cc",
- "cxxbridge-flags",
- "cxxbridge-macro",
- "link-cplusplus",
-]
-
-[[package]]
-name = "cxx-build"
-version = "1.0.86"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5044281f61b27bc598f2f6647d480aed48d2bf52d6eb0b627d84c0361b17aa70"
-dependencies = [
- "cc",
- "codespan-reporting",
- "once_cell",
- "proc-macro2",
- "quote",
- "scratch",
- "syn",
-]
-
-[[package]]
-name = "cxxbridge-flags"
-version = "1.0.86"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "61b50bc93ba22c27b0d31128d2d130a0a6b3d267ae27ef7e4fae2167dfe8781c"
-
-[[package]]
-name = "cxxbridge-macro"
-version = "1.0.86"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "39e61fda7e62115119469c7b3591fd913ecca96fb766cfd3f2e2502ab7bc87a5"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn",
-]
-
 [[package]]
 name = "data-encoding"
 version = "2.3.3"
@@ -907,7 +829,7 @@ checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31"
 dependencies = [
  "cfg-if",
  "libc",
- "wasi 0.11.0+wasi-snapshot-preview1",
+ "wasi",
 ]
 
 [[package]]
@@ -1084,30 +1006,6 @@ dependencies = [
  "tokio-native-tls",
 ]
 
-[[package]]
-name = "iana-time-zone"
-version = "0.1.53"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765"
-dependencies = [
- "android_system_properties",
- "core-foundation-sys",
- "iana-time-zone-haiku",
- "js-sys",
- "wasm-bindgen",
- "winapi",
-]
-
-[[package]]
-name = "iana-time-zone-haiku"
-version = "0.1.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca"
-dependencies = [
- "cxx",
- "cxx-build",
-]
-
 [[package]]
 name = "idna"
 version = "0.2.3"
@@ -1279,15 +1177,6 @@ dependencies = [
  "libc",
 ]
 
-[[package]]
-name = "link-cplusplus"
-version = "1.0.8"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5"
-dependencies = [
- "cc",
-]
-
 [[package]]
 name = "linked-hash-map"
 version = "0.5.6"
@@ -1435,7 +1324,7 @@ checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de"
 dependencies = [
  "libc",
  "log",
- "wasi 0.11.0+wasi-snapshot-preview1",
+ "wasi",
  "windows-sys",
 ]
 
@@ -2022,12 +1911,6 @@ version = "1.1.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
 
-[[package]]
-name = "scratch"
-version = "1.0.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ddccb15bcce173023b3fedd9436f882a0739b8dfb45e4f6b6002bee5929f61b2"
-
 [[package]]
 name = "sct"
 version = "0.7.0"
@@ -2339,17 +2222,6 @@ dependencies = [
  "once_cell",
 ]
 
-[[package]]
-name = "time"
-version = "0.1.45"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a"
-dependencies = [
- "libc",
- "wasi 0.10.0+wasi-snapshot-preview1",
- "winapi",
-]
-
 [[package]]
 name = "tinytemplate"
 version = "1.2.1"
@@ -2751,12 +2623,6 @@ dependencies = [
  "try-lock",
 ]
 
-[[package]]
-name = "wasi"
-version = "0.10.0+wasi-snapshot-preview1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
-
 [[package]]
 name = "wasi"
 version = "0.11.0+wasi-snapshot-preview1"
diff --git a/crates/binstalk-downloader/Cargo.toml b/crates/binstalk-downloader/Cargo.toml
index 073907d2..2f6e296b 100644
--- a/crates/binstalk-downloader/Cargo.toml
+++ b/crates/binstalk-downloader/Cargo.toml
@@ -12,7 +12,7 @@ license = "GPL-3.0"
 [dependencies]
 async-trait = "0.1.61"
 async-compression = { version = "0.3.15", features = ["gzip", "zstd", "xz", "bzip2", "tokio"] }
-async_zip = { version = "0.0.9", features = ["deflate", "bzip2", "lzma", "zstd", "xz"] }
+async_zip = { version = "0.0.10", features = ["deflate", "bzip2", "lzma", "zstd", "xz"] }
 binstalk-types = { version = "0.2.0", path = "../binstalk-types" }
 bytes = "1.3.0"
 bzip2 = "0.4.4"
diff --git a/crates/binstalk-downloader/src/download/async_extracter.rs b/crates/binstalk-downloader/src/download/async_extracter.rs
index 4850771e..6fd8d8a5 100644
--- a/crates/binstalk-downloader/src/download/async_extracter.rs
+++ b/crates/binstalk-downloader/src/download/async_extracter.rs
@@ -48,8 +48,10 @@ where
     let mut zip = ZipFileReader::new(reader);
     let mut buf = BytesMut::with_capacity(4 * 4096);
 
-    while let Some(entry) = zip.entry_reader().await.map_err(ZipError::from_inner)? {
-        extract_zip_entry(entry, path, &mut buf).await?;
+    while let Some(mut zip_reader) = zip.next_entry().await.map_err(ZipError::from_inner)? {
+        extract_zip_entry(&mut zip_reader, path, &mut buf).await?;
+
+        zip = zip_reader.done().await.map_err(ZipError::from_inner)?;
     }
 
     Ok(())
diff --git a/crates/binstalk-downloader/src/download/zip_extraction.rs b/crates/binstalk-downloader/src/download/zip_extraction.rs
index 89e4f2ab..2f13a9e6 100644
--- a/crates/binstalk-downloader/src/download/zip_extraction.rs
+++ b/crates/binstalk-downloader/src/download/zip_extraction.rs
@@ -3,12 +3,15 @@ use std::{
     path::{Component, Path, PathBuf},
 };
 
-use async_zip::{read::ZipEntryReader, ZipEntryExt};
+use async_zip::read::{
+    seek::ZipEntryReader,
+    stream::{Reading, ZipFileReader},
+};
 use bytes::{Bytes, BytesMut};
 use futures_util::future::{try_join, TryFutureExt};
 use thiserror::Error as ThisError;
 use tokio::{
-    io::{AsyncRead, AsyncReadExt},
+    io::{AsyncRead, AsyncReadExt, Take},
     sync::mpsc,
 };
 
@@ -34,7 +37,7 @@ impl ZipError {
 }
 
 pub(super) async fn extract_zip_entry<R>(
-    entry: ZipEntryReader<'_, R>,
+    zip_reader: &mut ZipFileReader<Reading<'_, Take<R>>>,
     path: &Path,
     buf: &mut BytesMut,
 ) -> Result<(), DownloadError>
@@ -42,7 +45,7 @@ where
     R: AsyncRead + Unpin + Send + Sync,
 {
     // Sanitize filename
-    let raw_filename = entry.entry().filename();
+    let raw_filename = zip_reader.entry().filename();
     let filename = check_filename_and_normalize(raw_filename)
         .ok_or_else(|| ZipError(ZipErrorInner::InvalidFilePath(raw_filename.into())))?;
 
@@ -56,7 +59,7 @@ where
     {
         use std::{fs::Permissions, os::unix::fs::PermissionsExt};
 
-        if let Some(mode) = entry.entry().unix_permissions() {
+        if let Some(mode) = zip_reader.entry().unix_permissions() {
             let mode: u16 = mode;
             perms = Some(Permissions::from_mode(mode as u32));
         }
@@ -98,7 +101,7 @@ where
                 Ok(())
             })
             .err_into(),
-            copy_file_to_mpsc(entry, tx, buf)
+            copy_file_to_mpsc(zip_reader.reader(), tx, buf)
                 .map_err(ZipError::from_inner)
                 .map_err(DownloadError::from),
         )
@@ -109,7 +112,7 @@ where
 }
 
 async fn copy_file_to_mpsc<R>(
-    mut entry: ZipEntryReader<'_, R>,
+    entry_reader: &mut ZipEntryReader<'_, R>,
     tx: mpsc::Sender<Bytes>,
     buf: &mut BytesMut,
 ) -> Result<(), async_zip::error::ZipError>
@@ -118,7 +121,7 @@ where
 {
     // Since BytesMut does not have a max cap, if AsyncReadExt::read_buf returns
     // 0 then it means Eof.
-    while entry.read_buf(buf).await? != 0 {
+    while entry_reader.read_buf(buf).await? != 0 {
         // Ensure AsyncReadExt::read_buf can read at least 4096B to avoid
         // frequent expensive read syscalls.
         //
@@ -143,11 +146,17 @@ where
         }
     }
 
-    if entry.compare_crc() {
+    // With async_zip 0.0.10, ZipEntryReader::compare_crc is removed.
+    // Hopefully it will restored later.
+
+    /*
+    if entry_reader.compare_crc() {
         Ok(())
     } else {
         Err(async_zip::error::ZipError::CRC32CheckError)
-    }
+    }*/
+
+    Ok(())
 }
 
 /// Ensure the file path is safe to use as a [`Path`].