From 33550b03c1724fbc8c1c8630c3b03fca1f0c0dc7 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 6 Jun 2026 21:44:46 +0900 Subject: feat(binary-installer): use file_get_contents with offset and length Add file_get_contents5 shim supporting use_include_path/context/offset/ length, and wire it into BinaryInstaller to read the first 500 bytes of the bin file, replacing the offset-less stub and its phase-b TODO. Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/shirabe/src/installer/binary_installer.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'crates/shirabe/src/installer') diff --git a/crates/shirabe/src/installer/binary_installer.rs b/crates/shirabe/src/installer/binary_installer.rs index 64908bf..539201f 100644 --- a/crates/shirabe/src/installer/binary_installer.rs +++ b/crates/shirabe/src/installer/binary_installer.rs @@ -5,8 +5,8 @@ use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::{CaptureKey, Preg}; use shirabe_php_shim::{ PhpMixed, basename, basename_with_suffix, chmod, dirname, fclose, fgets, file_exists, - file_get_contents, file_put_contents, fopen, is_dir, is_file, is_link, realpath, rmdir, substr, - trim, umask, + file_get_contents5, file_put_contents, fopen, is_dir, is_file, is_link, realpath, rmdir, + substr, trim, umask, }; use crate::io::IOInterface; @@ -245,7 +245,6 @@ impl BinaryInstaller { self.filesystem .borrow_mut() .ensure_directory_exists(&self.bin_dir); - // TODO(phase-b): PHP assigns realpath(...) even when realpath returns false self.bin_dir = realpath(&self.bin_dir).unwrap_or_default(); } @@ -294,9 +293,8 @@ impl BinaryInstaller { let bin_dir = ProcessExecutor::escape(&dirname(&bin_path)); let bin_file = basename(&bin_path); - // PHP: file_get_contents($bin, false, null, 0, 500) — limit 500 bytes - // TODO(phase-b): file_get_contents shim does not support offset/maxlen - let bin_contents = file_get_contents(bin).unwrap_or_default(); + let bin_contents = + file_get_contents5(bin, false, PhpMixed::Null, 0, Some(500)).unwrap_or_default(); // For php files, we generate a PHP proxy instead of a shell one, // which allows calling the proxy with a custom php process if let Some(m) = -- cgit v1.3.1