Revert "Bump async_zip from 0.0.9 to 0.0.10" (#714)

This commit is contained in:
Félix Saparelli 2023-01-17 13:08:25 +13:00 committed by GitHub
parent c2b1c243ea
commit c1332c0d2d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 153 additions and 30 deletions

View file

@ -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.10", features = ["deflate", "bzip2", "lzma", "zstd", "xz"] }
async_zip = { version = "0.0.9", features = ["deflate", "bzip2", "lzma", "zstd", "xz"] }
binstalk-types = { version = "0.2.0", path = "../binstalk-types" }
bytes = "1.3.0"
bzip2 = "0.4.4"

View file

@ -48,10 +48,8 @@ where
let mut zip = ZipFileReader::new(reader);
let mut buf = BytesMut::with_capacity(4 * 4096);
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)?;
while let Some(entry) = zip.entry_reader().await.map_err(ZipError::from_inner)? {
extract_zip_entry(entry, path, &mut buf).await?;
}
Ok(())

View file

@ -3,15 +3,12 @@ use std::{
path::{Component, Path, PathBuf},
};
use async_zip::read::{
seek::ZipEntryReader,
stream::{Reading, ZipFileReader},
};
use async_zip::{read::ZipEntryReader, ZipEntryExt};
use bytes::{Bytes, BytesMut};
use futures_util::future::{try_join, TryFutureExt};
use thiserror::Error as ThisError;
use tokio::{
io::{AsyncRead, AsyncReadExt, Take},
io::{AsyncRead, AsyncReadExt},
sync::mpsc,
};
@ -37,7 +34,7 @@ impl ZipError {
}
pub(super) async fn extract_zip_entry<R>(
zip_reader: &mut ZipFileReader<Reading<'_, Take<R>>>,
entry: ZipEntryReader<'_, R>,
path: &Path,
buf: &mut BytesMut,
) -> Result<(), DownloadError>
@ -45,7 +42,7 @@ where
R: AsyncRead + Unpin + Send + Sync,
{
// Sanitize filename
let raw_filename = zip_reader.entry().filename();
let raw_filename = entry.entry().filename();
let filename = check_filename_and_normalize(raw_filename)
.ok_or_else(|| ZipError(ZipErrorInner::InvalidFilePath(raw_filename.into())))?;
@ -59,7 +56,7 @@ where
{
use std::{fs::Permissions, os::unix::fs::PermissionsExt};
if let Some(mode) = zip_reader.entry().unix_permissions() {
if let Some(mode) = entry.entry().unix_permissions() {
let mode: u16 = mode;
perms = Some(Permissions::from_mode(mode as u32));
}
@ -101,7 +98,7 @@ where
Ok(())
})
.err_into(),
copy_file_to_mpsc(zip_reader.reader(), tx, buf)
copy_file_to_mpsc(entry, tx, buf)
.map_err(ZipError::from_inner)
.map_err(DownloadError::from),
)
@ -112,7 +109,7 @@ where
}
async fn copy_file_to_mpsc<R>(
entry_reader: &mut ZipEntryReader<'_, R>,
mut entry: ZipEntryReader<'_, R>,
tx: mpsc::Sender<Bytes>,
buf: &mut BytesMut,
) -> Result<(), async_zip::error::ZipError>
@ -121,7 +118,7 @@ where
{
// Since BytesMut does not have a max cap, if AsyncReadExt::read_buf returns
// 0 then it means Eof.
while entry_reader.read_buf(buf).await? != 0 {
while entry.read_buf(buf).await? != 0 {
// Ensure AsyncReadExt::read_buf can read at least 4096B to avoid
// frequent expensive read syscalls.
//
@ -146,17 +143,11 @@ where
}
}
// With async_zip 0.0.10, ZipEntryReader::compare_crc is removed.
// Hopefully it will restored later.
/*
if entry_reader.compare_crc() {
if entry.compare_crc() {
Ok(())
} else {
Err(async_zip::error::ZipError::CRC32CheckError)
}*/
Ok(())
}
}
/// Ensure the file path is safe to use as a [`Path`].