aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/shirabe/src/cache.rs7
-rw-r--r--crates/shirabe/src/command/base_config_command.rs6
-rw-r--r--crates/shirabe/src/command/bump_command.rs8
-rw-r--r--crates/shirabe/src/command/config_command.rs6
-rw-r--r--crates/shirabe/src/command/init_command.rs7
-rw-r--r--crates/shirabe/src/config/json_config_source.rs6
-rw-r--r--crates/shirabe/src/console/application.rs58
-rw-r--r--crates/shirabe/src/downloader/file_downloader.rs3
-rw-r--r--crates/shirabe/src/factory.rs19
-rw-r--r--crates/shirabe/src/installer/binary_installer.rs24
-rw-r--r--crates/shirabe/src/installer/library_installer.rs6
-rw-r--r--crates/shirabe/src/io/base_io.rs14
-rw-r--r--crates/shirabe/src/json/json_file.rs9
-rw-r--r--crates/shirabe/src/util/filesystem.rs8
-rw-r--r--crates/shirabe/src/util/http_downloader.rs3
-rw-r--r--crates/shirabe/src/util/platform.rs12
-rw-r--r--crates/shirabe/src/util/silencer.rs5
17 files changed, 55 insertions, 146 deletions
diff --git a/crates/shirabe/src/cache.rs b/crates/shirabe/src/cache.rs
index 269a31ef..ececa9fd 100644
--- a/crates/shirabe/src/cache.rs
+++ b/crates/shirabe/src/cache.rs
@@ -4,7 +4,6 @@ use crate::io::IOInterface;
use crate::io::IOInterfaceImmutable;
use crate::util::Filesystem;
use crate::util::Platform;
-use crate::util::Silencer;
use chrono::Utc;
use shirabe_php_shim::{
ErrorException, bin2hex, clearstatcache, date_format_to_strftime, dirname, disk_free_space,
@@ -105,9 +104,7 @@ impl Cache {
self.enabled = Some(true);
if !self.read_only
- && ((!is_dir(&self.root)
- && !Silencer::call(|| Ok(mkdir(&self.root, 0o777, true).is_ok()))
- .unwrap_or(false))
+ && ((!is_dir(&self.root) && mkdir(&self.root, 0o777, true).is_err())
|| !is_writable(&self.root))
{
self.io.write_error(&format!(
@@ -270,7 +267,7 @@ impl Cache {
Ok(_) => {
// fallback in case the above failed due to incorrect ownership
// see https://github.com/composer/composer/issues/4070
- Silencer::call(|| Ok(shirabe_php_shim::touch(&full_path)))?;
+ shirabe_php_shim::touch(&full_path);
}
Err(payload) => std::panic::resume_unwind(payload),
}
diff --git a/crates/shirabe/src/command/base_config_command.rs b/crates/shirabe/src/command/base_config_command.rs
index 3be49394..4ffbfadd 100644
--- a/crates/shirabe/src/command/base_config_command.rs
+++ b/crates/shirabe/src/command/base_config_command.rs
@@ -7,7 +7,6 @@ use crate::config::JsonConfigSource;
use crate::factory::Factory;
use crate::json::JsonFile;
use crate::util::Platform;
-use crate::util::Silencer;
use indexmap::IndexMap;
use shirabe_php_shim::{PhpMixed, chmod, touch};
use shirabe_symfony_console::input::InputInterface;
@@ -93,10 +92,7 @@ pub trait BaseConfigCommand: BaseCommand {
m.insert("config".to_string(), PhpMixed::Object(IndexMap::new()));
m
}))?;
- let _ = Silencer::call(|| {
- chmod(&path, 0o600);
- Ok(())
- });
+ chmod(&path, 0o600);
}
if !self.config_file().unwrap().borrow().exists() {
diff --git a/crates/shirabe/src/command/bump_command.rs b/crates/shirabe/src/command/bump_command.rs
index 9639cbe9..61d153ab 100644
--- a/crates/shirabe/src/command/bump_command.rs
+++ b/crates/shirabe/src/command/bump_command.rs
@@ -15,7 +15,6 @@ use crate::package::base_package;
use crate::package::version::VersionBumper;
use crate::repository::PlatformRepository;
use crate::util::Filesystem;
-use crate::util::Silencer;
use shirabe_php_shim::{
PhpMixed, file_get_contents, file_put_contents, impl_php_class, is_writable, php_regex,
preg_is_match, preg_replace, strtolower,
@@ -85,12 +84,7 @@ impl BumpCommand {
};
if !is_writable(&composer_json_path)
- && Silencer::call(|| {
- file_put_contents(&composer_json_path, &contents)
- .map(|_| ())
- .ok_or_else(|| anyhow::anyhow!("file_put_contents failed"))
- })
- .is_err()
+ && file_put_contents(&composer_json_path, &contents).is_none()
{
io.write_error3(
&format!("<error>{} is not writable.</error>", composer_json_path),
diff --git a/crates/shirabe/src/command/config_command.rs b/crates/shirabe/src/command/config_command.rs
index 2f3c5fd7..6c7e62f1 100644
--- a/crates/shirabe/src/command/config_command.rs
+++ b/crates/shirabe/src/command/config_command.rs
@@ -16,7 +16,6 @@ use crate::json::JsonFile;
use crate::package::base_package::{self};
use crate::util::Filesystem;
use crate::util::Platform;
-use crate::util::Silencer;
use indexmap::IndexMap;
use shirabe_php_shim::{
InvalidArgumentException, PhpMixed, RuntimeException, array_is_list, array_merge,
@@ -530,10 +529,7 @@ impl Command for ConfigCommand {
.borrow()
.write(PhpMixed::Array(empty_objs))?;
let path_clone = auth_config_file.borrow().get_path().to_string();
- Silencer::call(|| {
- shirabe_php_shim::chmod(&path_clone, 0o600);
- Ok(())
- });
+ shirabe_php_shim::chmod(&path_clone, 0o600);
}
Ok(())
}
diff --git a/crates/shirabe/src/command/init_command.rs b/crates/shirabe/src/command/init_command.rs
index 67530008..73285d62 100644
--- a/crates/shirabe/src/command/init_command.rs
+++ b/crates/shirabe/src/command/init_command.rs
@@ -17,7 +17,6 @@ use crate::repository::PlatformRepositoryHandle;
use crate::repository::RepositoryFactory;
use crate::util::Filesystem;
use crate::util::ProcessExecutor;
-use crate::util::Silencer;
use indexmap::IndexMap;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
@@ -675,11 +674,7 @@ impl Command for InitCommand {
true,
io_interface::NORMAL,
);
- let path_to_unlink = file_obj.get_path().to_string();
- let _ = Silencer::call(|| {
- shirabe_php_shim::unlink(&path_to_unlink);
- Ok::<(), anyhow::Error>(())
- });
+ let _ = shirabe_php_shim::unlink(file_obj.get_path());
return Ok(1);
}
diff --git a/crates/shirabe/src/config/json_config_source.rs b/crates/shirabe/src/config/json_config_source.rs
index 5e927398..dc2cb98e 100644
--- a/crates/shirabe/src/config/json_config_source.rs
+++ b/crates/shirabe/src/config/json_config_source.rs
@@ -5,7 +5,6 @@ use crate::json::JsonFile;
use crate::json::JsonManipulator;
use crate::json::JsonValidationException;
use crate::util::Filesystem;
-use crate::util::Silencer;
use indexmap::IndexMap;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
@@ -168,10 +167,7 @@ impl JsonConfigSource {
if new_file {
let path = self.file.borrow().get_path().to_string();
- let _ = Silencer::call(|| {
- chmod(&path, 0o600);
- Ok(())
- });
+ chmod(&path, 0o600);
}
Ok(())
diff --git a/crates/shirabe/src/console/application.rs b/crates/shirabe/src/console/application.rs
index 233ff751..d0d1bf0b 100644
--- a/crates/shirabe/src/console/application.rs
+++ b/crates/shirabe/src/console/application.rs
@@ -2075,22 +2075,16 @@ impl ApplicationHandle {
if uid != 0 {
// Silently clobber any sudo credentials on the invoking user to avoid privilege escalations later on
// ref. https://github.com/composer/composer/issues/5119
- let _ = Silencer::call(|| {
- shirabe_php_shim::exec(
- &format!("sudo -u \\#{} sudo -K > /dev/null 2>&1", uid),
- None,
- None,
- );
- Ok(())
- });
+ let _ = shirabe_php_shim::exec(
+ &format!("sudo -u \\#{} sudo -K > /dev/null 2>&1", uid),
+ None,
+ None,
+ );
}
}
// Silently clobber any remaining sudo leases on the current user as well to avoid privilege escalations
- let _ = Silencer::call(|| {
- shirabe_php_shim::exec("sudo -K > /dev/null 2>&1", None, None);
- Ok(())
- });
+ let _ = shirabe_php_shim::exec("sudo -K > /dev/null 2>&1", None, None);
}
// avoid loading plugins/initializing the Composer instance earlier than necessary if no plugin command is needed
@@ -2254,27 +2248,19 @@ impl ApplicationHandle {
}
// Check system temp folder for usability as it can cause weird runtime issues otherwise
- let tempfile_msg: Option<String> = Silencer::call(|| -> anyhow::Result<Option<String>> {
- let pid = format!("{}-", getmypid());
- let tempfile = format!(
- "{}/temp-{}{}",
- sys_get_temp_dir(),
- pid,
- bin2hex(&random_bytes(5))
- );
- if !(file_put_contents(&tempfile, file!().as_bytes()).is_some_and(|n| n > 0)
- && file_get_contents(&tempfile).as_deref().ok() == Some(file!().as_bytes())
- && unlink(&tempfile).is_ok()
- && !file_exists(&tempfile))
- {
- return Ok(Some(format!("<error>PHP temp directory ({}) does not exist or is not writable to Shirabe. Set sys_temp_dir in your php.ini</error>", sys_get_temp_dir())));
- }
- Ok(None)
- })
- .ok()
- .flatten();
- if let Some(msg) = tempfile_msg {
- io.write_error(&msg);
+ let pid = format!("{}-", getmypid());
+ let tempfile = format!(
+ "{}/temp-{}{}",
+ sys_get_temp_dir(),
+ pid,
+ bin2hex(&random_bytes(5))
+ );
+ if !(file_put_contents(&tempfile, file!().as_bytes()).is_some_and(|n| n > 0)
+ && file_get_contents(&tempfile).as_deref().ok() == Some(file!().as_bytes())
+ && unlink(&tempfile).is_ok()
+ && !file_exists(&tempfile))
+ {
+ io.write_error(&format!("<error>PHP temp directory ({}) does not exist or is not writable to Shirabe. Set sys_temp_dir in your php.ini</error>", sys_get_temp_dir()));
}
// add non-standard scripts as own commands
@@ -2530,11 +2516,7 @@ impl ApplicationHandle {
if let Some(ref owd) = old_working_dir
&& !owd.is_empty()
{
- let owd = owd.clone();
- let _ = Silencer::call(|| {
- chdir(&owd);
- Ok(())
- });
+ let _ = chdir(owd);
}
if let Some(st) = start_time {
diff --git a/crates/shirabe/src/downloader/file_downloader.rs b/crates/shirabe/src/downloader/file_downloader.rs
index 027205a0..84985286 100644
--- a/crates/shirabe/src/downloader/file_downloader.rs
+++ b/crates/shirabe/src/downloader/file_downloader.rs
@@ -21,7 +21,6 @@ use crate::util::Filesystem;
use crate::util::HttpDownloader;
use crate::util::Platform;
use crate::util::ProcessExecutor;
-use crate::util::Silencer;
use crate::util::Url as UrlUtil;
use crate::util::sync_executor;
use indexmap::IndexMap;
@@ -769,7 +768,7 @@ impl DownloaderInterface for FileDownloader {
for bin in package.get_binaries() {
let bin_path = format!("{}/{}", path, bin);
if file_exists(&bin_path) && !is_executable(&bin_path) {
- let _ = Silencer::call(|| Ok(shirabe_php_shim::chmod(&bin_path, 0o777 & !umask())));
+ shirabe_php_shim::chmod(&bin_path, 0o777 & !umask());
}
}
diff --git a/crates/shirabe/src/factory.rs b/crates/shirabe/src/factory.rs
index 6889a20d..8c696b1f 100644
--- a/crates/shirabe/src/factory.rs
+++ b/crates/shirabe/src/factory.rs
@@ -48,7 +48,6 @@ use crate::util::Filesystem;
use crate::util::HttpDownloader;
use crate::util::Platform;
use crate::util::ProcessExecutor;
-use crate::util::Silencer;
use crate::util::r#loop::Loop;
use indexmap::IndexMap;
use shirabe_php_shim::Catch as _;
@@ -135,10 +134,7 @@ impl Factory {
// select first dir which exists of: $XDG_CONFIG_HOME/shirabe or ~/.shirabe
for dir in &dirs {
- let dir_copy = dir.clone();
- let exists =
- Silencer::call(|| Ok::<bool, anyhow::Error>(is_dir(&dir_copy))).unwrap_or(false);
- if exists {
+ if is_dir(dir) {
return Ok(dir.clone());
}
}
@@ -177,7 +173,7 @@ impl Factory {
{
let from = format!("{}/cache", home);
let to = format!("{}/Library/Caches/shirabe", user_dir);
- let _ = Silencer::call(|| Ok::<bool, anyhow::Error>(rename(&from, &to)));
+ rename(&from, &to);
}
return Ok(format!("{}/Library/Caches/shirabe", user_dir));
@@ -298,15 +294,10 @@ impl Factory {
for dir in &dirs {
if !file_exists(format!("{}/.htaccess", dir)) {
if !is_dir(dir) {
- let dir_owned = dir.clone();
- let _ = Silencer::call(|| {
- Ok::<bool, anyhow::Error>(mkdir(&dir_owned, 0o777, true).is_ok())
- });
+ let _ = mkdir(dir, 0o777, true);
}
let path = format!("{}/.htaccess", dir);
- let _ = Silencer::call(|| {
- Ok::<Option<i64>, anyhow::Error>(file_put_contents(&path, b"Deny from all"))
- });
+ let _ = file_put_contents(&path, b"Deny from all");
}
}
}
@@ -1578,7 +1569,7 @@ impl Factory {
}
}
- Silencer::call(|| Ok::<bool, anyhow::Error>(is_dir("/etc/xdg"))).unwrap_or(false)
+ is_dir("/etc/xdg")
}
fn get_user_dir() -> anyhow::Result<String> {
diff --git a/crates/shirabe/src/installer/binary_installer.rs b/crates/shirabe/src/installer/binary_installer.rs
index 1f70a5ca..2da360d2 100644
--- a/crates/shirabe/src/installer/binary_installer.rs
+++ b/crates/shirabe/src/installer/binary_installer.rs
@@ -7,7 +7,6 @@ use crate::package::PackageInterfaceHandle;
use crate::util::Filesystem;
use crate::util::Platform;
use crate::util::ProcessExecutor;
-use crate::util::Silencer;
use shirabe_php_shim::{
basename, basename_with_suffix, chmod, dirname, fclose, fgets, file_exists,
file_get_contents_with_max_length, file_put_contents, fopen, is_dir, is_file, is_link,
@@ -152,10 +151,7 @@ impl BinaryInstaller {
} else {
self.install_unixy_proxy_binaries(&bin_path, &link);
}
- let _ = Silencer::call(|| {
- chmod(&bin_path, 0o777 & !umask());
- Ok(())
- });
+ chmod(&bin_path, 0o777 & !umask());
}
}
@@ -179,11 +175,7 @@ impl BinaryInstaller {
// attempt removing the bin dir in case it is left empty
if is_dir(&self.bin_dir) && self.filesystem.borrow_mut().is_dir_empty(&self.bin_dir) {
- let bin_dir = self.bin_dir.clone();
- let _ = Silencer::call(|| {
- rmdir(&bin_dir);
- Ok(())
- });
+ let _ = rmdir(&self.bin_dir);
}
}
@@ -241,22 +233,14 @@ impl BinaryInstaller {
if !file_exists(&link) {
let code = self.generate_windows_proxy_code(bin_path, &link);
file_put_contents(&link, code.as_bytes());
- let link_clone = link.clone();
- let _ = Silencer::call(|| {
- chmod(&link_clone, 0o777 & !umask());
- Ok(())
- });
+ chmod(&link, 0o777 & !umask());
}
}
fn install_unixy_proxy_binaries(&self, bin_path: &str, link: &str) {
let code = self.generate_unixy_proxy_code(bin_path, link);
file_put_contents(link, code.as_bytes());
- let link_owned = link.to_string();
- let _ = Silencer::call(|| {
- chmod(&link_owned, 0o777 & !umask());
- Ok(())
- });
+ chmod(link, 0o777 & !umask());
}
fn initialize_bin_dir(&mut self) {
diff --git a/crates/shirabe/src/installer/library_installer.rs b/crates/shirabe/src/installer/library_installer.rs
index d3bf4643..c4ac68a9 100644
--- a/crates/shirabe/src/installer/library_installer.rs
+++ b/crates/shirabe/src/installer/library_installer.rs
@@ -11,7 +11,6 @@ use crate::package::PackageInterfaceHandle;
use crate::repository::InstalledRepositoryInterfaceHandle;
use crate::util::Filesystem;
use crate::util::Platform;
-use crate::util::Silencer;
use shirabe_php_shim::{
InvalidArgumentException, LogicException, PhpMixed, dirname, is_dir, is_link, preg_quote,
preg_replace, realpath, rmdir, rtrim, strpos,
@@ -393,10 +392,7 @@ impl InstallerInterface for LibraryInstaller {
if is_dir(&package_vendor_dir)
&& self.filesystem.borrow().is_dir_empty(&package_vendor_dir)
{
- let _ = Silencer::call(|| {
- rmdir(&package_vendor_dir);
- Ok(())
- });
+ let _ = rmdir(&package_vendor_dir);
}
}
diff --git a/crates/shirabe/src/io/base_io.rs b/crates/shirabe/src/io/base_io.rs
index 4bc34ed6..0f3fd4e8 100644
--- a/crates/shirabe/src/io/base_io.rs
+++ b/crates/shirabe/src/io/base_io.rs
@@ -4,7 +4,6 @@ use crate::config::Config;
use crate::io::IOInterface;
use crate::io::io_interface;
use crate::util::ProcessExecutor;
-use crate::util::Silencer;
use indexmap::IndexMap;
use shirabe_php_shim::{
JSON_INVALID_UTF8_IGNORE, JSON_UNESCAPED_SLASHES, JSON_UNESCAPED_UNICODE, PhpMixed,
@@ -435,14 +434,11 @@ pub trait BaseIO: IOInterface {
let mut message_str = message.to_string();
if !context.is_empty() {
- let json: anyhow::Result<Option<String>> = Silencer::call(|| {
- Ok(json_encode_ex(
- &PhpMixed::Array(log_context(context)),
- JSON_INVALID_UTF8_IGNORE | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE,
- )
- .ok())
- });
- if let Ok(Some(json_str)) = json {
+ let json = json_encode_ex(
+ &PhpMixed::Array(log_context(context)),
+ JSON_INVALID_UTF8_IGNORE | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE,
+ );
+ if let Ok(json_str) = json {
message_str += " ";
message_str += &json_str;
}
diff --git a/crates/shirabe/src/json/json_file.rs b/crates/shirabe/src/json/json_file.rs
index 703b9fbb..eafe27e7 100644
--- a/crates/shirabe/src/json/json_file.rs
+++ b/crates/shirabe/src/json/json_file.rs
@@ -7,7 +7,6 @@ use crate::io::io_interface;
use crate::json::JsonValidationException;
use crate::util::Filesystem;
use crate::util::HttpDownloader;
-use crate::util::Silencer;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
InvalidArgumentException, JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, JSON_UNESCAPED_UNICODE,
@@ -239,8 +238,7 @@ impl JsonFile {
))
.into());
}
- // PHP: @mkdir($dir, 0777, true)
- if !Silencer::call(|| Ok(mkdir(&dir, 0o777, true).is_ok())).unwrap_or(false) {
+ if mkdir(&dir, 0o777, true).is_err() {
return Err(UnexpectedValueException::new(format!(
"{} does not exist and could not be created.",
dir
@@ -285,10 +283,7 @@ impl JsonFile {
path: &str,
content: &str,
) -> anyhow::Result<Option<i64>> {
- // PHP: @file_get_contents($path)
- let current_content = Silencer::call(|| Ok(file_get_contents(path).ok()))
- .ok()
- .flatten();
+ let current_content = file_get_contents(path).ok();
if current_content.is_none() || current_content.as_deref() != Some(content.as_bytes()) {
return Ok(file_put_contents(path, content.as_bytes()));
}
diff --git a/crates/shirabe/src/util/filesystem.rs b/crates/shirabe/src/util/filesystem.rs
index b20f5f48..3e8e3e04 100644
--- a/crates/shirabe/src/util/filesystem.rs
+++ b/crates/shirabe/src/util/filesystem.rs
@@ -2,7 +2,6 @@
use crate::util::Platform;
use crate::util::ProcessExecutor;
-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,
@@ -810,11 +809,11 @@ impl Filesystem {
}
if is_file(path) {
- return Silencer::call(|| Ok(file_get_contents(path).is_ok())).unwrap_or(false);
+ return file_get_contents(path).is_ok();
}
if is_dir(path) {
- return Silencer::call(|| Ok(std::fs::read_dir(path).is_ok())).unwrap_or(false);
+ return std::fs::read_dir(path).is_ok();
}
// assume false otherwise
@@ -1022,8 +1021,7 @@ impl Filesystem {
}
pub fn file_put_contents_if_modified(&self, path: &str, content: &str) -> anyhow::Result<i64> {
- let current_content =
- Silencer::call(|| Ok(file_get_contents(path).unwrap_or_default())).unwrap_or_default();
+ let current_content = file_get_contents(path).unwrap_or_default();
if current_content.is_empty() || current_content != content.as_bytes() {
return Ok(file_put_contents(path, content.as_bytes()).unwrap_or(0));
}
diff --git a/crates/shirabe/src/util/http_downloader.rs b/crates/shirabe/src/util/http_downloader.rs
index f9f69c9b..32327a75 100644
--- a/crates/shirabe/src/util/http_downloader.rs
+++ b/crates/shirabe/src/util/http_downloader.rs
@@ -9,7 +9,6 @@ use crate::package::version::VersionParser;
use crate::util::GetResult;
use crate::util::Platform;
use crate::util::RemoteFilesystem;
-use crate::util::Silencer;
use crate::util::StreamContextFactory;
use crate::util::Url;
use crate::util::http::CurlDownloader;
@@ -452,7 +451,6 @@ impl HttpDownloader {
if strpos(e_as_transport.get_message(), "Resolving timed out").is_some()
|| strpos(e_as_transport.get_message(), "Could not resolve host").is_some()
{
- Silencer::suppress(None);
let mut ctx_options: IndexMap<String, PhpMixed> = IndexMap::new();
let mut ssl_map: IndexMap<String, PhpMixed> = IndexMap::new();
ssl_map.insert("verify_peer".to_string(), PhpMixed::Bool(false));
@@ -465,7 +463,6 @@ impl HttpDownloader {
// until the PHP stream-context layer is modeled.
let _ = stream_context_create(&ctx_options, None);
let test_connectivity = file_get_contents("https://8.8.8.8");
- Silencer::restore();
if test_connectivity.is_ok() {
return Some(vec![
"<error>The following exception probably indicates you have misconfigured DNS resolver(s)</error>".to_string(),
diff --git a/crates/shirabe/src/util/platform.rs b/crates/shirabe/src/util/platform.rs
index bb3dd739..3a95af7e 100644
--- a/crates/shirabe/src/util/platform.rs
+++ b/crates/shirabe/src/util/platform.rs
@@ -1,7 +1,6 @@
//! ref: composer/src/Composer/Util/Platform.php
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, function_exists, getcwd, getenv, ini_get, is_readable,
@@ -164,10 +163,7 @@ impl Platform {
return false;
}
- let file_contents = Silencer::call(|| Ok(file_get_contents("/proc/version").ok()))
- .ok()
- .flatten()
- .unwrap_or_default();
+ let file_contents = file_get_contents("/proc/version").unwrap_or_default();
if !ini_get("open_basedir").is_some_and(|s| PhpMixed::String(s).to_bool())
&& is_readable("/proc/version")
// TODO(bytes)
@@ -220,11 +216,7 @@ impl Platform {
}
// suppress errors as some environments have these files as readable but system restrictions prevent the read from succeeding
// see https://github.com/composer/composer/issues/12095
- let data = match Silencer::call(|| Ok(file_get_contents(cgroup))) {
- Ok(d) => d,
- Err(_) => break,
- };
- let data = match data {
+ let data = match file_get_contents(cgroup) {
Ok(d) => d,
Err(_) => continue,
};
diff --git a/crates/shirabe/src/util/silencer.rs b/crates/shirabe/src/util/silencer.rs
index 7286689a..e2b2ac9e 100644
--- a/crates/shirabe/src/util/silencer.rs
+++ b/crates/shirabe/src/util/silencer.rs
@@ -35,6 +35,11 @@ impl Silencer {
}
}
+ /// Wrap a callable only when it can reach the PHP runtime, where a plugin may emit diagnostics
+ /// of its own; the same holds for a region bracketed by `suppress` and `restore`. Work that
+ /// stays inside Rust has no `error_reporting()` level to lower and emits no diagnostic on
+ /// failure, and errors it raises propagate either way, so silencing it is indistinguishable
+ /// from running it unguarded. Run it unguarded instead.
pub fn call<F, T>(callable: F) -> anyhow::Result<T>
where
F: FnOnce() -> anyhow::Result<T>,