aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/util/tar.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-01 05:26:16 +0900
committernsfisis <nsfisis@gmail.com>2026-08-01 18:41:11 +0900
commit06d2c5c884eee0b5b663730f4d379a7ceae3a8e4 (patch)
tree5cd768e0bdad3f8a056dd9b047de363963315135 /crates/shirabe/src/util/tar.rs
parentb8d46b0495d00815a699932ced0b43955c949ab9 (diff)
downloadphp-shirabe-06d2c5c884eee0b5b663730f4d379a7ceae3a8e4.tar.gz
php-shirabe-06d2c5c884eee0b5b663730f4d379a7ceae3a8e4.tar.zst
php-shirabe-06d2c5c884eee0b5b663730f4d379a7ceae3a8e4.zip
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 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/util/tar.rs')
-rw-r--r--crates/shirabe/src/util/tar.rs17
1 files changed, 14 insertions, 3 deletions
diff --git a/crates/shirabe/src/util/tar.rs b/crates/shirabe/src/util/tar.rs
index 55b6a960..792d1c4f 100644
--- a/crates/shirabe/src/util/tar.rs
+++ b/crates/shirabe/src/util/tar.rs
@@ -7,7 +7,7 @@ pub struct Tar;
impl Tar {
pub fn get_composer_json(path_to_archive: &str) -> anyhow::Result<Option<String>> {
- let phar = PharData::new(path_to_archive.to_string());
+ let phar = PharData::new(path_to_archive.to_string())?;
if !phar.valid() {
return Ok(None);
@@ -16,9 +16,20 @@ impl Tar {
Ok(Some(Self::extract_composer_json_from_folder(&phar)?))
}
+ /// The content bytes are decoded strictly: a composer.json that is not valid
+ /// UTF-8 could never survive the JSON parsing that follows in PHP either.
+ fn content_to_string(content: Vec<u8>) -> anyhow::Result<String> {
+ String::from_utf8(content).map_err(|_| {
+ anyhow::anyhow!(RuntimeException {
+ message: "composer.json in the archive is not valid UTF-8".to_string(),
+ code: 0,
+ })
+ })
+ }
+
fn extract_composer_json_from_folder(phar: &PharData) -> anyhow::Result<String> {
if let Some(file) = phar.get("composer.json") {
- return Ok(file.get_content());
+ return Self::content_to_string(file.get_content());
}
let mut top_level_paths: IndexMap<String, bool> = IndexMap::new();
@@ -49,7 +60,7 @@ impl Tar {
if !top_level_paths.is_empty()
&& let Some(file) = phar.get(&composer_json_path)
{
- return Ok(file.get_content());
+ return Self::content_to_string(file.get_content());
}
Err(anyhow::anyhow!(RuntimeException {