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. --- .../src/php_file_parser.rs | 9 +---- .../src/output/console_output.rs | 6 +-- crates/shirabe-symfony-console/src/terminal.rs | 9 ----- crates/shirabe-symfony-process/src/process.rs | 7 ---- crates/shirabe/src/cache.rs | 16 +++----- crates/shirabe/src/console/application.rs | 36 ++++++------------ crates/shirabe/src/downloader/path_downloader.rs | 17 +-------- crates/shirabe/src/downloader/zip_downloader.rs | 38 +++++-------------- .../shirabe/src/package/archiver/phar_archiver.rs | 6 +-- crates/shirabe/src/package/locker.rs | 9 +---- .../shirabe/src/package/version/version_guesser.rs | 10 ++--- crates/shirabe/src/util/filesystem.rs | 44 +++++----------------- crates/shirabe/src/util/http_downloader.rs | 6 +-- crates/shirabe/src/util/platform.rs | 32 ++-------------- crates/shirabe/src/util/stream_context_factory.rs | 16 ++------ 15 files changed, 59 insertions(+), 202 deletions(-) (limited to 'crates') diff --git a/crates/shirabe-class-map-generator/src/php_file_parser.rs b/crates/shirabe-class-map-generator/src/php_file_parser.rs index b7fb595c..0cb9180f 100644 --- a/crates/shirabe-class-map-generator/src/php_file_parser.rs +++ b/crates/shirabe-class-map-generator/src/php_file_parser.rs @@ -2,9 +2,8 @@ use crate::php_file_cleaner::PhpFileCleaner; use shirabe_php_shim::{ - PHP_EOL, RuntimeException, file_exists, file_get_contents, function_exists, is_file, - is_readable, ltrim, php_strip_whitespace, preg_match_all, str_replace_array, strrpos, substr, - trim, + PHP_EOL, RuntimeException, file_exists, file_get_contents, is_file, is_readable, ltrim, + php_strip_whitespace, preg_match_all, str_replace_array, strrpos, substr, trim, }; use std::sync::OnceLock; @@ -14,10 +13,6 @@ impl PhpFileParser { pub fn find_classes(path: &str) -> anyhow::Result> { let extra_types = Self::get_extra_types(); - if !function_exists("php_strip_whitespace") { - return Err(RuntimeException::new("Classmap generation relies on the php_strip_whitespace function, but it has been disabled by the disable_functions directive.".to_string()).into()); - } - // Use @ here instead of Silencer to actively suppress 'unhelpful' output let contents = match php_strip_whitespace(path) { Ok(contents) if !contents.is_empty() => contents, diff --git a/crates/shirabe-symfony-console/src/output/console_output.rs b/crates/shirabe-symfony-console/src/output/console_output.rs index 4080d688..9c2904db 100644 --- a/crates/shirabe-symfony-console/src/output/console_output.rs +++ b/crates/shirabe-symfony-console/src/output/console_output.rs @@ -98,11 +98,7 @@ impl ConsoleOutput { /// doesn't properly convert character-encodings between ASCII to EBCDIC. fn is_running_os400() -> bool { let checks = [ - if shirabe_php_shim::function_exists("php_uname") { - shirabe_php_shim::php_uname("s") - } else { - String::new() - }, + shirabe_php_shim::php_uname("s"), shirabe_php_shim::getenv("OSTYPE") .unwrap_or_default() .to_string_lossy() diff --git a/crates/shirabe-symfony-console/src/terminal.rs b/crates/shirabe-symfony-console/src/terminal.rs index 492d8fe2..c7bc82b8 100644 --- a/crates/shirabe-symfony-console/src/terminal.rs +++ b/crates/shirabe-symfony-console/src/terminal.rs @@ -62,11 +62,6 @@ impl Terminal { return stty; } - // skip check if shell_exec function is disabled - if !shirabe_php_shim::function_exists("shell_exec") { - return false; - } - let result = shirabe_php_shim::shell_exec(&format!( "stty 2> {}", if cfg!(windows) { "NUL" } else { "/dev/null" } @@ -195,10 +190,6 @@ impl Terminal { } fn read_from_process(command: &str) -> Option { - if !shirabe_php_shim::function_exists("proc_open") { - return None; - } - // Sparse PHP descriptorspec `[1 => ['pipe', 'w'], 2 => ['pipe', 'w']]`: fd 0 is inherited. let descriptorspec = [ shirabe_php_shim::Descriptor::Inherit, diff --git a/crates/shirabe-symfony-process/src/process.rs b/crates/shirabe-symfony-process/src/process.rs index 991bdd08..06e60cab 100644 --- a/crates/shirabe-symfony-process/src/process.rs +++ b/crates/shirabe-symfony-process/src/process.rs @@ -213,13 +213,6 @@ impl Process { input: PhpMixed, timeout: Option, ) -> anyhow::Result { - if !shirabe_php_shim::function_exists("proc_open") { - return Err(LogicException::new( - "The Process class relies on proc_open, which is not available on your PHP installation.".to_string(), - ) - .into()); - } - let mut this = Self::empty(); this.commandline = CommandLine::Array(command); this.cwd = cwd; diff --git a/crates/shirabe/src/cache.rs b/crates/shirabe/src/cache.rs index edfe584c..a8e4fb26 100644 --- a/crates/shirabe/src/cache.rs +++ b/crates/shirabe/src/cache.rs @@ -8,9 +8,9 @@ use crate::util::Silencer; use chrono::Utc; use shirabe_php_shim::{ ErrorException, bin2hex, clearstatcache, date_format_to_strftime, dirname, disk_free_space, - file_exists, file_get_contents, file_put_contents, filemtime, function_exists, hash_file, - is_dir, is_writable, mkdir, php_regex, preg_is_match, preg_match, preg_replace, random_bytes, - random_int, rename, time, unlink, + file_exists, file_get_contents, file_put_contents, filemtime, hash_file, is_dir, is_writable, + mkdir, php_regex, preg_is_match, preg_match, preg_replace, random_bytes, random_int, rename, + time, unlink, }; use shirabe_symfony_finder::Finder; use std::sync::Mutex; @@ -195,13 +195,9 @@ impl Cache { // Remove partial file. unlink(&temp_file_name); - let free_space = if function_exists("disk_free_space") { - disk_free_space(dirname(&temp_file_name)) - .map(|space| space.to_string()) - .unwrap_or_default() - } else { - "unknown".to_string() - }; + let free_space = disk_free_space(dirname(&temp_file_name)) + .map(|space| space.to_string()) + .unwrap_or_default(); let message = format!( "Writing {} into cache failed after {} of {} bytes written, only {} bytes of free space available", temp_file_name, diff --git a/crates/shirabe/src/console/application.rs b/crates/shirabe/src/console/application.rs index 54df0b05..d73a1c6b 100644 --- a/crates/shirabe/src/console/application.rs +++ b/crates/shirabe/src/console/application.rs @@ -246,7 +246,7 @@ impl Application { // avoid overlapping borrows of self (get_composer needs &mut self). let disk_hint_msg: Option = (|| -> anyhow::Result> { let composer = self.get_composer(false, Some(true), None)?; - if let Some(composer) = composer && function_exists("disk_free_space") { + if let Some(composer) = composer { let composer = composer.borrow_partial(); let config = composer.get_config(); @@ -1536,9 +1536,7 @@ impl Application { input.borrow_mut().set_interactive(false); } - if shirabe_php_shim::function_exists("putenv") { - unsafe { shirabe_php_shim::putenv("SHELL_VERBOSITY", shell_verbosity.to_string()) }; - } + unsafe { shirabe_php_shim::putenv("SHELL_VERBOSITY", shell_verbosity.to_string()) }; shirabe_php_shim::PHP_ENV .lock() .unwrap() @@ -2106,7 +2104,6 @@ impl ApplicationHandle { } let needs_sudo_check = !Platform::is_windows() - && function_exists("exec") && Platform::get_env("COMPOSER_ALLOW_SUPERUSER").is_none() && !Platform::is_docker(); let mut is_non_allowed_root = false; @@ -2243,16 +2240,13 @@ impl ApplicationHandle { if !is_proxy_command { io.write_error3( &format!( - "Running Shirabe {} ({}, based on Composer {}) with PHP {} on {}", + "Running Shirabe {} ({}, based on Composer {}) with PHP {} on {} / {}", composer::SHIRABE_VERSION, composer::SHIRABE_RELEASE_DATE, composer::VERSION, shirabe_php_rpc::get_php_version().version, - (if function_exists("php_uname") { - format!("{} / {}", php_uname("s"), php_uname("r")) - } else { - "Unknown OS".to_string() - }), + php_uname("s"), + php_uname("r"), ), true, io_interface::DEBUG, @@ -2305,11 +2299,7 @@ impl ApplicationHandle { // Check system temp folder for usability as it can cause weird runtime issues otherwise let tempfile_msg: Option = Silencer::call(|| -> anyhow::Result> { - let pid = if function_exists("getmypid") { - format!("{}-", getmypid()) - } else { - String::new() - }; + let pid = format!("{}-", getmypid()); let tempfile = format!( "{}/temp-{}{}", sys_get_temp_dir(), @@ -2688,14 +2678,12 @@ impl ApplicationHandle { output: Option>>, ) -> anyhow::Result { let application = &self.0; - if shirabe_php_shim::function_exists("putenv") { - let (height, width) = { - let app = application.borrow(); - (app.terminal.get_height(), app.terminal.get_width()) - }; - unsafe { shirabe_php_shim::putenv("LINES", height.to_string()) }; - unsafe { shirabe_php_shim::putenv("COLUMNS", width.to_string()) }; - } + let (height, width) = { + let app = application.borrow(); + (app.terminal.get_height(), app.terminal.get_width()) + }; + unsafe { shirabe_php_shim::putenv("LINES", height.to_string()) }; + unsafe { shirabe_php_shim::putenv("COLUMNS", width.to_string()) }; let input: std::rc::Rc> = match input { None => std::rc::Rc::new(std::cell::RefCell::new(ArgvInput::new(None, None)?)), 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."); } } } diff --git a/crates/shirabe/src/package/archiver/phar_archiver.rs b/crates/shirabe/src/package/archiver/phar_archiver.rs index ea04a302..75e5a775 100644 --- a/crates/shirabe/src/package/archiver/phar_archiver.rs +++ b/crates/shirabe/src/package/archiver/phar_archiver.rs @@ -7,7 +7,7 @@ use indexmap::IndexMap; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ FilesystemIterator, Phar, PharData, RuntimeException, UnexpectedValueException, bzcompress, - file_exists, file_put_contents, function_exists, gzcompress, str_repeat, strrpos, unlink, + file_exists, file_put_contents, gzcompress, str_repeat, strrpos, unlink, }; fn formats() -> IndexMap<&'static str, i64> { @@ -108,11 +108,11 @@ impl ArchiverInterface for PharArchiver { )) .into()); } - if format == "tar.gz" && function_exists("gzcompress") { + if format == "tar.gz" { let data = gzcompress(&str_repeat("\0", 10240).into_bytes()).unwrap_or_default(); file_put_contents(&target, &data); - } else if format == "tar.bz2" && function_exists("bzcompress") { + } else if format == "tar.bz2" { let data = bzcompress(&str_repeat("\0", 10240).into_bytes()).unwrap_or_default(); file_put_contents(&target, &data); diff --git a/crates/shirabe/src/package/locker.rs b/crates/shirabe/src/package/locker.rs index ec8d86e7..17911c6e 100644 --- a/crates/shirabe/src/package/locker.rs +++ b/crates/shirabe/src/package/locker.rs @@ -27,9 +27,8 @@ use indexmap::IndexMap; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ DATE_RFC3339, LogicException, PhpMixed, RuntimeException, array_intersect, array_keys, - array_map, array_merge, file_get_contents, filemtime, function_exists, hash, in_array_loose, - is_int, ksort, php_regex, preg_is_match, preg_match, realpath, strcmp, strtolower, touch2, - trim, usort, + array_map, array_merge, file_get_contents, filemtime, hash, in_array_loose, is_int, ksort, + php_regex, preg_is_match, preg_match, realpath, strcmp, strtolower, touch2, trim, usort, }; use shirabe_seld_json_lint::ParsingException; @@ -773,10 +772,6 @@ impl Locker { &mut self, package: PackageInterfaceHandle, ) -> anyhow::Result> { - if !function_exists("proc_open") { - return Ok(None); - } - let path = self .installation_manager .borrow_mut() diff --git a/crates/shirabe/src/package/version/version_guesser.rs b/crates/shirabe/src/package/version/version_guesser.rs index 3c47d5b2..38c4f0a3 100644 --- a/crates/shirabe/src/package/version/version_guesser.rs +++ b/crates/shirabe/src/package/version/version_guesser.rs @@ -13,9 +13,9 @@ use crate::util::Svn as SvnUtil; use crate::util::sync_executor; use indexmap::IndexMap; use shirabe_php_shim::{ - PhpMixed, RuntimeException, array_keys, array_map, array_merge, empty, function_exists, - implode, is_string, json_encode, php_regex, preg_is_match, preg_match, preg_quote, - preg_replace, str_replace, strlen, strnatcasecmp, strpos, substr, trim, usort, + PhpMixed, RuntimeException, array_keys, array_map, array_merge, empty, implode, is_string, + json_encode, php_regex, preg_is_match, preg_match, preg_quote, preg_replace, str_replace, + strlen, strnatcasecmp, strpos, substr, trim, usort, }; /// Seam over the parts of [`VersionGuesser`] that consumers depend on, so they can be exercised @@ -104,10 +104,6 @@ impl VersionGuesser { return Ok(None); } - if !function_exists("proc_open") { - return Ok(None); - } - // bypass version guessing in bash completions as it takes time to create // new processes and the root version is usually not that important if Platform::is_input_completion_process() { diff --git a/crates/shirabe/src/util/filesystem.rs b/crates/shirabe/src/util/filesystem.rs index 41b81b7b..2395d1cd 100644 --- a/crates/shirabe/src/util/filesystem.rs +++ b/crates/shirabe/src/util/filesystem.rs @@ -6,11 +6,11 @@ use crate::util::Silencer; use shirabe_php_shim::{ ErrorException, LogicException, PhpMixed, PregMatches, RuntimeException, array_pop, basename, chdir, clearstatcache, clearstatcache2, copy, dirname, explode, fclose, feof, file_exists, - file_get_contents, file_put_contents, fileatime, filemtime, filesize, fopen, fread, - function_exists, fwrite, implode, is_dir, is_file, is_link, is_readable, lstat, mkdir, - php_regex, preg_is_match, preg_match, preg_replace, preg_replace_callback, rename, rmdir, - rtrim, str_repeat, str_replace, strlen, strpos, strtoupper, strtr, substr, substr_count, - symlink, touch, unlink, usleep, var_export, + file_get_contents, file_put_contents, fileatime, filemtime, filesize, fopen, fread, fwrite, + implode, is_dir, is_file, is_link, is_readable, lstat, mkdir, php_regex, preg_is_match, + preg_match, preg_replace, preg_replace_callback, rename, rmdir, rtrim, str_repeat, str_replace, + strlen, strpos, strtoupper, strtr, substr, substr_count, symlink, touch, unlink, usleep, + var_export, }; use shirabe_symfony_filesystem::exception::IOException; use shirabe_symfony_finder::Finder; @@ -114,9 +114,6 @@ impl Filesystem { } /// Recursively remove a directory - /// - /// Uses the process component if proc_open is enabled on the PHP - /// installation. pub fn remove_directory(&mut self, directory: impl AsRef) -> anyhow::Result { // TODO(bytes): // This path is matched against a regex (remove_edge_cases) and passed to an @@ -129,7 +126,7 @@ impl Filesystem { directory.display() )) })?; - let edge_case_result = self.remove_edge_cases(directory, true)?; + let edge_case_result = self.remove_edge_cases(directory)?; if let Some(r) = edge_case_result { return Ok(r); } @@ -167,13 +164,6 @@ impl Filesystem { } /// Recursively remove a directory asynchronously - /// - /// Uses the process component if proc_open is enabled on the PHP - /// installation. - /// - /// Takes the shared handle instead of `&mut self`: the Filesystem is borrowed only for the - /// synchronous head and tail, never across the subprocess await, so sibling futures can keep - /// using the same `Rc>` while the removal runs. pub async fn remove_directory_async_via( this: &std::rc::Rc>, directory: &str, @@ -189,7 +179,7 @@ impl Filesystem { return Ok(result); } - let edge_case_result = fs.remove_edge_cases(directory, true)?; + let edge_case_result = fs.remove_edge_cases(directory)?; if let Some(r) = edge_case_result { return Ok(r); } @@ -225,11 +215,7 @@ impl Filesystem { } /// Returns null when no edge case was hit. Otherwise a bool whether removal was successful - fn remove_edge_cases( - &mut self, - directory: &str, - fallback_to_php: bool, - ) -> anyhow::Result> { + fn remove_edge_cases(&mut self, directory: &str) -> anyhow::Result> { if self.is_symlinked_directory(directory) { return Ok(Some(self.unlink_symlinked_directory(directory)?)); } @@ -251,10 +237,6 @@ impl Filesystem { .into()); } - if !function_exists("proc_open") && fallback_to_php { - return Ok(Some(self.remove_directory_php(directory)?)); - } - Ok(None) } @@ -264,7 +246,7 @@ impl Filesystem { /// before directories, creating a single non-recursive loop /// to delete files/directories in the correct order. pub fn remove_directory_php(&mut self, directory: &str) -> anyhow::Result { - let edge_case_result = self.remove_edge_cases(directory, false)?; + let edge_case_result = self.remove_edge_cases(directory)?; if let Some(r) = edge_case_result { return Ok(r); } @@ -497,10 +479,6 @@ impl Filesystem { RuntimeException::new(format!("Path contains invalid UTF-8: {}", target.display())) })?; - if !function_exists("proc_open") { - return self.copy_then_remove(source, target); - } - if Platform::is_windows() { // Try to copy & delete - this is a workaround for random "Access denied" errors. let mut output = String::new(); @@ -884,10 +862,6 @@ impl Filesystem { /// Creates a relative symlink from $link to $target pub fn relative_symlink(&self, target: &str, link: &str) -> bool { - if !function_exists("symlink") { - return false; - } - let cwd = Platform::get_cwd(false).unwrap_or_default(); let relative_path = self.find_shortest_path(link, target, false, false); diff --git a/crates/shirabe/src/util/http_downloader.rs b/crates/shirabe/src/util/http_downloader.rs index 36ccb712..8d34dcdf 100644 --- a/crates/shirabe/src/util/http_downloader.rs +++ b/crates/shirabe/src/util/http_downloader.rs @@ -19,8 +19,8 @@ use indexmap::IndexMap; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ InvalidArgumentException, LogicException, PhpMixed, array_replace_recursive, extension_loaded, - file_get_contents, function_exists, implode, is_numeric, php_regex, preg_is_match, preg_match, - preg_replace, rawurldecode, stream_context_create, stripos, strpos, substr, ucfirst, + file_get_contents, implode, is_numeric, php_regex, preg_is_match, preg_match, preg_replace, + rawurldecode, stream_context_create, stripos, strpos, substr, ucfirst, }; use shirabe_semver::constraint::SimpleConstraint; @@ -505,8 +505,6 @@ impl HttpDownloader { /// @internal pub fn is_curl_enabled() -> bool { extension_loaded("curl") - && function_exists("curl_multi_exec") - && function_exists("curl_multi_init") } /// For testing only. Builds an HttpDownloader whose request methods are fully diff --git a/crates/shirabe/src/util/platform.rs b/crates/shirabe/src/util/platform.rs index ccee2953..c40f3ec5 100644 --- a/crates/shirabe/src/util/platform.rs +++ b/crates/shirabe/src/util/platform.rs @@ -4,8 +4,8 @@ use crate::util::ProcessExecutor; use crate::util::Silencer; use shirabe_php_shim::{ PHP_ENV, PHP_SERVER, PhpMixed, PhpResource, PregMatches, RuntimeException, defined, - file_exists, file_get_contents, fstat, function_exists, getcwd, getenv, ini_get, is_readable, - mb_strlen, php_os_family, php_regex, posix_geteuid, posix_getpwuid, posix_getuid, posix_isatty, + file_exists, file_get_contents, function_exists, getcwd, getenv, ini_get, is_readable, + mb_strlen, php_os_family, php_regex, posix_geteuid, posix_getpwuid, posix_getuid, preg_is_match, preg_replace_callback, putenv, putenv_clear, realpath, stream_isatty, stripos, strlen, strtoupper, substr, usleep, }; @@ -244,9 +244,7 @@ impl Platform { let mut use_mb_string = USE_MB_STRING.lock().unwrap(); if use_mb_string.is_none() { *use_mb_string = Some( - function_exists("mb_strlen") - && ini_get("mbstring.func_overload") - .is_some_and(|s| PhpMixed::String(s).to_bool()), + ini_get("mbstring.func_overload").is_some_and(|s| PhpMixed::String(s).to_bool()), ); } @@ -270,29 +268,7 @@ impl Platform { return true; } - // modern cross-platform function, includes the fstat - // fallback so if it is present we trust it - if function_exists("stream_isatty") { - return stream_isatty(fd); - } - - // only trusting this if it is positive, otherwise prefer fstat fallback - if function_exists("posix_isatty") && posix_isatty(fd.clone()) { - return true; - } - - let stat = Silencer::call(|| Ok(fstat(&fd))); - let stat = match stat { - Ok(s) => s, - Err(_) => return false, - }; - let stat = match stat { - Some(stat) => stat, - None => return false, - }; - - // Check if formatted mode is S_IFCHR - 0o020000 == (stat.mode & 0o170000) + stream_isatty(fd) } /// Whether the current command is for bash completion diff --git a/crates/shirabe/src/util/stream_context_factory.rs b/crates/shirabe/src/util/stream_context_factory.rs index dea964ec..bce35832 100644 --- a/crates/shirabe/src/util/stream_context_factory.rs +++ b/crates/shirabe/src/util/stream_context_factory.rs @@ -9,8 +9,8 @@ use crate::util::http::ProxyManager; use indexmap::IndexMap; use shirabe_ca_bundle::CaBundle; use shirabe_php_shim::{ - PhpMixed, array_replace_recursive, extension_loaded, function_exists, php_uname, - stream_context_create, stripos, uasort, + PhpMixed, array_replace_recursive, extension_loaded, php_uname, stream_context_create, stripos, + uasort, }; pub struct StreamContextFactory; @@ -180,16 +180,8 @@ impl StreamContextFactory { let user_agent = format!( "User-Agent: Composer/{} ({os}; {release}; {php_version}; {http_version}{platform}{ci})", composer::get_version(), - os = if function_exists("php_uname") { - php_uname("s") - } else { - "Unknown".to_string() - }, - release = if function_exists("php_uname") { - php_uname("r") - } else { - "Unknown".to_string() - }, + os = php_uname("s"), + release = php_uname("r"), php_version = php_version, http_version = http_version, platform = platform_php_version -- cgit v1.3.1-4-g156e