From 06d2c5c884eee0b5b663730f4d379a7ceae3a8e4 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 1 Aug 2026 05:26:16 +0900 Subject: feat(php-shim): implement Phar/PharData and the zlib/bzip2 functions Adopt the tar, flate2, and bzip2 crates to fill in the phar.rs and compress.rs todos: PharData tar/zip reading, building, and whole-archive compression, plus a native .phar reader that follows the php.net file-format manual and verifies hash-based signatures. Callers now propagate the constructor/extract errors PHP throws, and fwrite accepts byte strings so gzread no longer needs lossy UTF-8. The native .phar writing API stays todo!() (no call sites; Composer's Compiler is not ported) and OPENSSL phar signatures are accepted unverified (TODO(phase-c)). This unblocks Tar::getComposerJson and the tar/phar/gzip downloaders; tar_test (7), artifact_repository_test (2), and phar_archiver_test zip (1) are un-ignored. The archive command itself still panics because ArchiveManager::archive always generates glob excludes whose look-ahead regexes the regex crate cannot compile; converting those patterns to regex-compatible ones is a separate, still-undecided work item. Co-Authored-By: Claude Fable 5 --- crates/shirabe/src/package/archiver/archivable_files_filter.rs | 5 +++-- crates/shirabe/src/package/archiver/phar_archiver.rs | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'crates/shirabe/src/package/archiver') diff --git a/crates/shirabe/src/package/archiver/archivable_files_filter.rs b/crates/shirabe/src/package/archiver/archivable_files_filter.rs index ee39ba37..02a622f7 100644 --- a/crates/shirabe/src/package/archiver/archivable_files_filter.rs +++ b/crates/shirabe/src/package/archiver/archivable_files_filter.rs @@ -24,11 +24,12 @@ impl ArchivableFilesFilter { true } - pub fn add_empty_dir(&self, phar: &PharData, sources: &str) { + pub fn add_empty_dir(&self, phar: &PharData, sources: &str) -> anyhow::Result<()> { for filepath in &self.dirs { let localname = filepath.replace(&format!("{}/", sources), ""); - phar.add_empty_dir(&localname); + phar.add_empty_dir(&localname)?; } + Ok(()) } } diff --git a/crates/shirabe/src/package/archiver/phar_archiver.rs b/crates/shirabe/src/package/archiver/phar_archiver.rs index 1bac060b..55e4cb95 100644 --- a/crates/shirabe/src/package/archiver/phar_archiver.rs +++ b/crates/shirabe/src/package/archiver/phar_archiver.rs @@ -73,11 +73,11 @@ impl ArchiverInterface for PharArchiver { FilesystemIterator::KEY_AS_PATHNAME | FilesystemIterator::CURRENT_AS_FILEINFO, "", *formats.get(format.as_str()).unwrap_or(&Phar::TAR), - ); + )?; let files = ArchivableFilesFinder::new(&sources, excludes, ignore_filters)?; let mut files_only = ArchivableFilesFilter::new(Box::new(files)); - phar.build_from_iterator(&mut files_only, &sources); - files_only.add_empty_dir(&phar, &sources); + phar.build_from_iterator(&mut files_only, &sources)?; + files_only.add_empty_dir(&phar, &sources)?; if !file_exists(&target) { let target = format!("{}.{}", filename, format); @@ -137,7 +137,7 @@ impl ArchiverInterface for PharArchiver { unlink(&target); - phar.compress(compress_algo); + phar.compress(compress_algo)?; let target = format!("{}.{}", filename, format); return Ok(target); -- cgit v1.3.1