diff options
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/shirabe-php-shim/src/zip.rs | 39 | ||||
| -rw-r--r-- | crates/shirabe/src/downloader/zip_downloader.rs | 7 |
2 files changed, 15 insertions, 31 deletions
diff --git a/crates/shirabe-php-shim/src/zip.rs b/crates/shirabe-php-shim/src/zip.rs index 4fab9aad..fe566ae4 100644 --- a/crates/shirabe-php-shim/src/zip.rs +++ b/crates/shirabe-php-shim/src/zip.rs @@ -1,7 +1,5 @@ use crate::ErrorException; -use crate::PhpMixed; use crate::{StreamBacking, StreamState}; -use indexmap::IndexMap; use zip::write::SimpleFileOptions; /// Test-only behaviour mirroring PHPUnit's `getMockBuilder('ZipArchive')->getMock()`, where @@ -32,6 +30,14 @@ enum ZipState { }, } +/// One entry of an archive, as returned by [`ZipArchive::stat_index`]. Only fields that Composer +/// accesses are ported. +#[derive(Debug, Clone)] +pub struct ZipEntryStat { + pub size: i64, + pub comp_size: i64, +} + #[derive(Debug)] pub struct ZipArchive { pub num_files: i64, @@ -113,35 +119,16 @@ impl ZipArchive { self.num_files } - pub fn stat_index(&self, index: i64) -> Option<IndexMap<String, PhpMixed>> { + pub fn stat_index(&self, index: i64) -> Option<ZipEntryStat> { let mut state = self.state.borrow_mut(); let ZipState::Reader(archive) = &mut *state else { return None; }; let file = archive.by_index(index as usize).ok()?; - let mut stat = IndexMap::new(); - stat.insert( - "name".to_string(), - PhpMixed::String(file.name().to_string()), - ); - stat.insert("index".to_string(), PhpMixed::Int(index)); - stat.insert("crc".to_string(), PhpMixed::Int(file.crc32() as i64)); - stat.insert("size".to_string(), PhpMixed::Int(file.size() as i64)); - // PHP exposes the last-modified time as a Unix timestamp. The `zip` crate - // only surfaces a 2-second-precision MS-DOS datetime; no consumer reads - // this field, so it is reported as 0 rather than reconstructing it. - stat.insert("mtime".to_string(), PhpMixed::Int(0)); - stat.insert( - "comp_size".to_string(), - PhpMixed::Int(file.compressed_size() as i64), - ); - let comp_method = match file.compression() { - zip::CompressionMethod::Stored => 0, - zip::CompressionMethod::Deflated => 8, - _ => -1, - }; - stat.insert("comp_method".to_string(), PhpMixed::Int(comp_method)); - Some(stat) + Some(ZipEntryStat { + size: file.size() as i64, + comp_size: file.compressed_size() as i64, + }) } pub fn extract_to(&self, path: impl AsRef<std::path::Path>) -> Result<bool, ErrorException> { diff --git a/crates/shirabe/src/downloader/zip_downloader.rs b/crates/shirabe/src/downloader/zip_downloader.rs index a63aca18..cdb9307c 100644 --- a/crates/shirabe/src/downloader/zip_downloader.rs +++ b/crates/shirabe/src/downloader/zip_downloader.rs @@ -309,11 +309,8 @@ impl ZipDownloader { random_int(0..total_files) }; if let Some(stat) = zip_archive.stat_index(stat_index) { - let size = stat.get("size").and_then(|v| v.as_int()).unwrap_or(0); - let comp_size = - stat.get("comp_size").and_then(|v| v.as_int()).unwrap_or(0); - total_size += size; - if !inspect_all && size > comp_size * 200 { + total_size += stat.size; + if !inspect_all && stat.size > stat.comp_size * 200 { total_size = 0; inspect_all = true; i = -1; |
