aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/util/filesystem.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-14 11:24:36 +0900
committernsfisis <nsfisis@gmail.com>2026-06-14 11:28:19 +0900
commit716f44031a39c5e43fb441ecc470db76efc23dd4 (patch)
treee6f4a31e4bf55a0a8efb06d9dd4844c567e7390f /crates/shirabe/src/util/filesystem.rs
parentef9118c788c1cbb22ca7721b6a9e40c2bf2fe243 (diff)
downloadphp-shirabe-716f44031a39c5e43fb441ecc470db76efc23dd4.tar.gz
php-shirabe-716f44031a39c5e43fb441ecc470db76efc23dd4.tar.zst
php-shirabe-716f44031a39c5e43fb441ecc470db76efc23dd4.zip
refactor(pcre): drop Result from Preg method return types
The Preg methods panic on PCRE failure (per the file header rationale), so their anyhow::Result wrappers never carried an Err. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/util/filesystem.rs')
-rw-r--r--crates/shirabe/src/util/filesystem.rs24
1 files changed, 9 insertions, 15 deletions
diff --git a/crates/shirabe/src/util/filesystem.rs b/crates/shirabe/src/util/filesystem.rs
index 15f970d..cb0e4a5 100644
--- a/crates/shirabe/src/util/filesystem.rs
+++ b/crates/shirabe/src/util/filesystem.rs
@@ -193,7 +193,7 @@ impl Filesystem {
return Ok(Some(true));
}
- if Preg::is_match3("{^(?:[a-z]:)?[/\\\\]+$}i", directory, None).unwrap_or(false) {
+ if Preg::is_match3("{^(?:[a-z]:)?[/\\\\]+$}i", directory, None) {
return Err(RuntimeException {
message: format!("Aborting an attempted deletion of {}, this was probably not intended, if it is a real use case please report it.", directory),
code: 0,
@@ -541,7 +541,7 @@ impl Filesystem {
let mut common_path = to.clone();
while strpos(&format!("{}/", from), &format!("{}/", common_path)) != Some(0)
&& "/" != common_path
- && !Preg::is_match3("{^[A-Z]:/?$}i", &common_path, None).unwrap_or(false)
+ && !Preg::is_match3("{^[A-Z]:/?$}i", &common_path, None)
{
common_path = strtr(&dirname(&common_path), "\\", "/");
}
@@ -602,7 +602,7 @@ impl Filesystem {
let mut common_path = to.clone();
while strpos(&format!("{}/", from), &format!("{}/", common_path)) != Some(0)
&& "/" != common_path
- && !Preg::is_match3("{^[A-Z]:/?$}i", &common_path, None).unwrap_or(false)
+ && !Preg::is_match3("{^[A-Z]:/?$}i", &common_path, None)
&& "." != common_path
{
common_path = strtr(&dirname(&common_path), "\\", "/");
@@ -705,9 +705,7 @@ impl Filesystem {
"{^( [0-9a-z]{2,}+: (?: // (?: [a-z]: )? )? | [a-z]: )}ix",
&path,
Some(&mut prefix_match),
- )
- .unwrap_or(false)
- {
+ ) {
prefix = prefix_match
.get(&shirabe_external_packages::composer::pcre::CaptureKey::ByIndex(1))
.cloned()
@@ -746,8 +744,7 @@ impl Filesystem {
strtoupper(&s)
},
&prefix,
- )
- .unwrap_or_default();
+ );
format!("{}{}{}", prefix, absolute, implode("/", &parts))
}
@@ -757,7 +754,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::is_match3("{^[/\\\\]+$}", &path, None).unwrap_or(false) {
+ if !Preg::is_match3("{^[/\\\\]+$}", &path, None) {
path = rtrim(&path, Some("/\\"));
}
@@ -773,8 +770,7 @@ impl Filesystem {
"{^(file://(?!//)|/(?!/)|/?[a-z]:[\\\\/]|\\.\\.[\\\\/]|[a-z0-9_.-]+[\\\\/])}i",
path,
None,
- )
- .unwrap_or(false);
+ );
}
Preg::is_match3(
@@ -782,17 +778,15 @@ impl Filesystem {
path,
None,
)
- .unwrap_or(false)
}
pub fn get_platform_path(path: &str) -> String {
let mut path = path.to_string();
if Platform::is_windows() {
- path = Preg::replace("{^(?:file:///([a-z]):?/)}i", "file://$1:/", &path)
- .unwrap_or_default();
+ path = Preg::replace("{^(?:file:///([a-z]):?/)}i", "file://$1:/", &path);
}
- Preg::replace("{^file://}i", "", &path).unwrap_or_default()
+ Preg::replace("{^file://}i", "", &path)
}
/// Cross-platform safe version of is_readable()