From ced1f9aa91ee36857fec9664c9ccd86ba2310821 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Tue, 18 Aug 2026 04:47:02 +0900 Subject: refactor(function-exists): drop checks for always-present capabilities function_exists() returns false in PHP when a function is blocked by disable_functions, when its extension is not compiled in, or when the PHP version predates it. None of those apply to a native binary. --- crates/shirabe/src/downloader/path_downloader.rs | 17 +---------- crates/shirabe/src/downloader/zip_downloader.rs | 38 +++++++----------------- 2 files changed, 11 insertions(+), 44 deletions(-) (limited to 'crates/shirabe/src/downloader') diff --git a/crates/shirabe/src/downloader/path_downloader.rs b/crates/shirabe/src/downloader/path_downloader.rs index 6b3531f4..a96d8db7 100644 --- a/crates/shirabe/src/downloader/path_downloader.rs +++ b/crates/shirabe/src/downloader/path_downloader.rs @@ -21,9 +21,7 @@ use crate::util::HttpDownloader; use crate::util::Platform; use crate::util::ProcessExecutor; use indexmap::IndexMap; -use shirabe_php_shim::{ - PhpMixed, RuntimeException, file_exists, function_exists, impl_php_class, is_dir, realpath, -}; +use shirabe_php_shim::{PhpMixed, RuntimeException, file_exists, impl_php_class, is_dir, realpath}; use shirabe_symfony_filesystem::Filesystem as SymfonyFilesystem; #[derive(Debug)] @@ -160,19 +158,6 @@ impl PathDownloader { allowed_strategies = vec![Self::STRATEGY_MIRROR]; } - // Check we can use symlink() otherwise - if !Platform::is_windows() - && Self::STRATEGY_SYMLINK == current_strategy - && !function_exists("symlink") - { - if !allowed_strategies.contains(&Self::STRATEGY_MIRROR) { - return Err(RuntimeException::new("Your PHP has the symlink() function disabled which does not allow Shirabe to use symlinks and this path repository has symlink:true in its options so copying is not allowed".to_string()) - .into()); - } - current_strategy = Self::STRATEGY_MIRROR; - allowed_strategies = vec![Self::STRATEGY_MIRROR]; - } - Ok((current_strategy, allowed_strategies)) } diff --git a/crates/shirabe/src/downloader/zip_downloader.rs b/crates/shirabe/src/downloader/zip_downloader.rs index 565005d9..a63aca18 100644 --- a/crates/shirabe/src/downloader/zip_downloader.rs +++ b/crates/shirabe/src/downloader/zip_downloader.rs @@ -11,9 +11,9 @@ use indexmap::IndexMap; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ CmpOp, ErrorException, PhpMixed, RuntimeException, UnexpectedValueException, ZipArchive, - bin2hex, class_exists, file_exists, file_get_contents, filesize, function_exists, hash_file, - impl_php_class, is_file, json_encode, php_regex, preg_match, random_int, str_replace, strlen, - substr, version_compare, + bin2hex, class_exists, file_exists, file_get_contents, filesize, hash_file, impl_php_class, + is_file, json_encode, php_regex, preg_match, random_int, str_replace, strlen, substr, + version_compare, }; use shirabe_symfony_process::ExecutableFinder; use std::sync::Mutex; @@ -528,11 +528,6 @@ impl crate::downloader::DownloaderInterface for ZipDownloader { } } - let proc_open_missing = !function_exists("proc_open"); - if proc_open_missing { - *UNZIP_COMMANDS.lock().unwrap() = Some(vec![]); - } - { let mut has_zip_archive = HAS_ZIP_ARCHIVE.lock().unwrap(); if has_zip_archive.is_none() { @@ -549,17 +544,10 @@ impl crate::downloader::DownloaderInterface for ZipDownloader { if !has_zip_archive && unzip_commands_empty { let ini_message = IniHelper::get_message(); - let error = if proc_open_missing { - format!( - "The zip extension is missing and unzip/7z commands cannot be called as proc_open is disabled, skipping.\n{}", - ini_message - ) - } else { - format!( - "The zip extension and unzip/7z commands are both missing, skipping.\n{}", - ini_message - ) - }; + let error = format!( + "The zip extension and unzip/7z commands are both missing, skipping.\n{}", + ini_message + ); return Err(RuntimeException::new(error).into()); } @@ -569,15 +557,9 @@ impl crate::downloader::DownloaderInterface for ZipDownloader { *is_windows_guard = Some(Platform::is_windows()); if !is_windows_guard.unwrap() && unzip_commands_empty { - if proc_open_missing { - self.inner.io.borrow().write_error("proc_open is disabled so 'unzip' and '7z' commands cannot be used, zip files are being unpacked using the PHP zip extension."); - self.inner.io.borrow().write_error("This may cause invalid reports of corrupted archives. Besides, any UNIX permissions (e.g. executable) defined in the archives will be lost."); - self.inner.io.borrow().write_error("Enabling proc_open and installing 'unzip' or '7z' (21.01+) may remediate them."); - } else { - self.inner.io.borrow().write_error("As there is no 'unzip' nor '7z' command installed zip files are being unpacked using the PHP zip extension."); - self.inner.io.borrow().write_error("This may cause invalid reports of corrupted archives. Besides, any UNIX permissions (e.g. executable) defined in the archives will be lost."); - self.inner.io.borrow().write_error("Installing 'unzip' or '7z' (21.01+) may remediate them."); - } + self.inner.io.borrow().write_error("As there is no 'unzip' nor '7z' command installed zip files are being unpacked using the PHP zip extension."); + self.inner.io.borrow().write_error("This may cause invalid reports of corrupted archives. Besides, any UNIX permissions (e.g. executable) defined in the archives will be lost."); + self.inner.io.borrow().write_error("Installing 'unzip' or '7z' (21.01+) may remediate them."); } } } -- cgit v1.3.1-4-g156e