aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/util/filesystem.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-18 01:57:02 +0900
committernsfisis <nsfisis@gmail.com>2026-08-18 01:57:02 +0900
commitfed0a6e7ac361af9b963c1f62411b1a85478230c (patch)
tree5cde64a24845c761890fbcbe05e0d702f1ec8df7 /crates/shirabe/src/util/filesystem.rs
parente093b2be1c333e67c96aebb0a5291bea9ae3d6db (diff)
downloadphp-shirabe-fed0a6e7ac361af9b963c1f62411b1a85478230c.tar.gz
php-shirabe-fed0a6e7ac361af9b963c1f62411b1a85478230c.tar.zst
php-shirabe-fed0a6e7ac361af9b963c1f62411b1a85478230c.zip
refactor(preg): add preg_is_match for existence-only call sites
The capture groups were discarded at 162 of the preg_match call sites, which only tested the Option. They now call preg_is_match, which lets the regex engine skip capture tracking. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/util/filesystem.rs')
-rw-r--r--crates/shirabe/src/util/filesystem.rs22
1 files changed, 10 insertions, 12 deletions
diff --git a/crates/shirabe/src/util/filesystem.rs b/crates/shirabe/src/util/filesystem.rs
index ae19a998..41b81b7b 100644
--- a/crates/shirabe/src/util/filesystem.rs
+++ b/crates/shirabe/src/util/filesystem.rs
@@ -8,9 +8,9 @@ use shirabe_php_shim::{
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_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,
+ 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;
@@ -246,7 +246,7 @@ impl Filesystem {
return Ok(Some(true));
}
- if preg_match(php_regex!("{^(?:[a-z]:)?[/\\\\]+$}i"), directory).is_some() {
+ if preg_is_match(php_regex!("{^(?:[a-z]:)?[/\\\\]+$}i"), directory) {
return Err(RuntimeException::new(format!("Aborting an attempted deletion of {}, this was probably not intended, if it is a real use case please report it.", directory))
.into());
}
@@ -578,7 +578,7 @@ impl Filesystem {
let mut common_path = to.clone();
while strpos(&format!("{}/", from), &format!("{}/", common_path)) != Some(0)
&& "/" != common_path
- && preg_match(php_regex!("{^[A-Z]:/?$}i"), &common_path).is_none()
+ && !preg_is_match(php_regex!("{^[A-Z]:/?$}i"), &common_path)
{
common_path = strtr(&dirname(&common_path), "\\", "/");
}
@@ -635,7 +635,7 @@ impl Filesystem {
let mut common_path = to.clone();
while strpos(&format!("{}/", from), &format!("{}/", common_path)) != Some(0)
&& "/" != common_path
- && preg_match(php_regex!("{^[A-Z]:/?$}i"), &common_path).is_none()
+ && !preg_is_match(php_regex!("{^[A-Z]:/?$}i"), &common_path)
&& "." != common_path
{
common_path = strtr(&dirname(&common_path), "\\", "/");
@@ -778,7 +778,7 @@ impl Filesystem {
/// And other possible unforeseen disasters, see https://github.com/composer/composer/pull/9422
pub fn trim_trailing_slash(path: &str) -> String {
let mut path = path.to_string();
- if preg_match(php_regex!("{^[/\\\\]+$}"), &path).is_none() {
+ if !preg_is_match(php_regex!("{^[/\\\\]+$}"), &path) {
path = rtrim(&path, Some("/\\"));
}
@@ -790,20 +790,18 @@ impl Filesystem {
// on windows, \\foo indicates network paths so we exclude those from local paths, however it is unsafe
// on linux as file:////foo (which would be a network path \\foo on windows) will resolve to /foo which could be a local path
if Platform::is_windows() {
- return preg_match(
+ return preg_is_match(
php_regex!(
"{^(file://(?!//)|/(?!/)|/?[a-z]:[\\\\/]|\\.\\.[\\\\/]|[a-z0-9_.-]+[\\\\/])}i"
),
path,
- )
- .is_some();
+ );
}
- preg_match(
+ preg_is_match(
php_regex!("{^(file://|/|/?[a-z]:[\\\\/]|\\.\\.[\\\\/]|[a-z0-9_.-]+[\\\\/])}i"),
path,
)
- .is_some()
}
pub fn get_platform_path(path: &str) -> String {