aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe/src/util')
-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
4 files changed, 10 insertions, 18 deletions
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>,