From eacd2abcc53659a9fa20b1274a30ac4d9ad8bdb6 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Wed, 3 Jun 2026 20:10:17 +0900 Subject: feat(php-shim): align fwrite/touch2/PHP_OS_FAMILY/PHP_URL_SCHEME with PHP Adjust fwrite to return int|false equivalent (Option), add touch2 with mtime, implement PHP_OS_FAMILY via std::env::consts::OS, and swap the PHP_URL_HOST placeholders for the now-available PHP_URL_SCHEME. Wire these into locker, filesystem, platform, and remote_filesystem. Co-Authored-By: Claude Opus 4.8 --- crates/shirabe/src/util/filesystem.rs | 6 +++--- crates/shirabe/src/util/platform.rs | 11 ++++------- crates/shirabe/src/util/remote_filesystem.rs | 9 +++------ 3 files changed, 10 insertions(+), 16 deletions(-) (limited to 'crates/shirabe/src/util') diff --git a/crates/shirabe/src/util/filesystem.rs b/crates/shirabe/src/util/filesystem.rs index ef3d307..c7f3583 100644 --- a/crates/shirabe/src/util/filesystem.rs +++ b/crates/shirabe/src/util/filesystem.rs @@ -405,9 +405,9 @@ impl Filesystem { while !feof(source_handle.clone()) { let chunk = fread(source_handle.clone(), 1024 * 1024).unwrap_or_default(); - // TODO(phase-b): PHP fwrite returns int|false; shim currently returns (); - // assume success here. - fwrite(target_handle.clone(), &chunk, chunk.len() as i64); + if fwrite(target_handle.clone(), &chunk, chunk.len() as i64).is_none() { + return Err(e.into()); + } } fclose(source_handle); fclose(target_handle); diff --git a/crates/shirabe/src/util/platform.rs b/crates/shirabe/src/util/platform.rs index 541fd56..ecc362c 100644 --- a/crates/shirabe/src/util/platform.rs +++ b/crates/shirabe/src/util/platform.rs @@ -7,9 +7,9 @@ use shirabe_external_packages::composer::pcre::Preg; use shirabe_php_shim::{ PhpMixed, RuntimeException, defined, env_contains_key, env_get, env_set, env_unset, file_exists, file_get_contents, fopen, fstat, function_exists, getcwd, getenv, in_array, - ini_get, is_array, is_readable, mb_strlen, posix_geteuid, posix_getpwuid, posix_getuid, - posix_isatty, putenv, realpath, server_argv, server_contains_key, server_get, server_set, - server_unset, stream_isatty, stripos, strlen, strtoupper, substr, usleep, + ini_get, is_array, is_readable, mb_strlen, php_os_family, posix_geteuid, posix_getpwuid, + posix_getuid, posix_isatty, putenv, realpath, server_argv, server_contains_key, server_get, + server_set, server_unset, stream_isatty, stripos, strlen, strtoupper, substr, usleep, }; use crate::util::ProcessExecutor; @@ -397,10 +397,7 @@ impl Platform { return true; } - if defined("PHP_OS_FAMILY") - // TODO(phase-b): PHP_OS_FAMILY constant comparison - && true - { + if php_os_family() == "Linux" { let mut process = ProcessExecutor::new(None); // TODO(phase-b): inner Result for catch(\Exception); use anyhow::Result> let mut output = String::new(); diff --git a/crates/shirabe/src/util/remote_filesystem.rs b/crates/shirabe/src/util/remote_filesystem.rs index 22f5ea2..2773300 100644 --- a/crates/shirabe/src/util/remote_filesystem.rs +++ b/crates/shirabe/src/util/remote_filesystem.rs @@ -4,7 +4,7 @@ use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::{CaptureKey, Preg}; use shirabe_php_shim::{ - FILTER_VALIDATE_BOOLEAN, PHP_URL_HOST, PHP_URL_PATH, PHP_VERSION_ID, PhpMixed, + FILTER_VALIDATE_BOOLEAN, PHP_URL_HOST, PHP_URL_PATH, PHP_URL_SCHEME, PHP_VERSION_ID, PhpMixed, RuntimeException, STREAM_NOTIFY_FAILURE, STREAM_NOTIFY_FILE_SIZE_IS, STREAM_NOTIFY_PROGRESS, array_replace_recursive, base64_encode, explode, extension_loaded, file_put_contents, filter_var, gethostbyname, http_clear_last_response_headers, http_get_last_response_headers, @@ -177,8 +177,7 @@ impl RemoteFilesystem { file_name: Option, progress: bool, ) -> anyhow::Result { - // TODO(phase-b): PHP_URL_SCHEME constant isn't yet in the shim; PHP_URL_HOST stands in. - self.scheme = parse_url(&strtr(file_url, "\\", "/"), PHP_URL_HOST) + self.scheme = parse_url(&strtr(file_url, "\\", "/"), PHP_URL_SCHEME) .as_string() .unwrap_or("") .to_string(); @@ -928,12 +927,10 @@ impl RemoteFilesystem { ) -> anyhow::Result> { let mut target_url: Option = None; if let Some(location_header) = Response::find_header_value(response_headers, "location") { - // TODO(phase-b): use PHP_URL_SCHEME once available to detect absolute URLs. - if !parse_url(&location_header, PHP_URL_HOST) + if !parse_url(&location_header, PHP_URL_SCHEME) .as_string() .unwrap_or("") .is_empty() - && location_header.contains("://") { target_url = Some(location_header); } else if parse_url(&location_header, PHP_URL_HOST) -- cgit v1.3.1