aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/downloader
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/downloader
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/downloader')
-rw-r--r--crates/shirabe/src/downloader/download_manager.rs2
-rw-r--r--crates/shirabe/src/downloader/fossil_downloader.rs4
-rw-r--r--crates/shirabe/src/downloader/git_downloader.rs51
-rw-r--r--crates/shirabe/src/downloader/svn_downloader.rs48
-rw-r--r--crates/shirabe/src/downloader/zip_downloader.rs4
5 files changed, 42 insertions, 67 deletions
diff --git a/crates/shirabe/src/downloader/download_manager.rs b/crates/shirabe/src/downloader/download_manager.rs
index 209c6ee..3d4fe9b 100644
--- a/crates/shirabe/src/downloader/download_manager.rs
+++ b/crates/shirabe/src/downloader/download_manager.rs
@@ -459,7 +459,7 @@ impl DownloadManager {
"{{^{}$}}i",
str_replace("\\*", ".*", &preg_quote(pattern, None)),
);
- if Preg::is_match(&pattern_regex, &package.get_name()).unwrap_or(false) {
+ if Preg::is_match(&pattern_regex, &package.get_name()) {
if "dist" == preference || (!package.is_dev() && "auto" == preference) {
return "dist".to_string();
}
diff --git a/crates/shirabe/src/downloader/fossil_downloader.rs b/crates/shirabe/src/downloader/fossil_downloader.rs
index d6b8095..2c4e7de 100644
--- a/crates/shirabe/src/downloader/fossil_downloader.rs
+++ b/crates/shirabe/src/downloader/fossil_downloader.rs
@@ -238,11 +238,11 @@ impl VcsDownloader for FossilDownloader {
let lines: Vec<String> = if trimmed.is_empty() {
vec![]
} else {
- Preg::split(r"{\r?\n}", &trimmed)?
+ Preg::split(r"{\r?\n}", &trimmed)
};
for line in lines {
- if Preg::is_match(&match_pattern, &line)? {
+ if Preg::is_match(&match_pattern, &line) {
break;
}
log.push_str(&line);
diff --git a/crates/shirabe/src/downloader/git_downloader.rs b/crates/shirabe/src/downloader/git_downloader.rs
index fd2246a..c38e491 100644
--- a/crates/shirabe/src/downloader/git_downloader.rs
+++ b/crates/shirabe/src/downloader/git_downloader.rs
@@ -99,9 +99,7 @@ impl GitDownloader {
let mut refs = trim(&output, None);
let mut head_match: IndexMap<CaptureKey, String> = IndexMap::new();
- if !Preg::is_match3(r"{^([a-f0-9]+) HEAD$}mi", &refs, Some(&mut head_match))
- .unwrap_or(false)
- {
+ if !Preg::is_match3(r"{^([a-f0-9]+) HEAD$}mi", &refs, Some(&mut head_match)) {
// could not match the HEAD for some reason
return Ok(None);
}
@@ -115,9 +113,7 @@ impl GitDownloader {
&format!("{{^{} refs/heads/(.+)$}}mi", preg_quote(&head_ref, None)),
&refs,
Some(&mut branches_match),
- )
- .unwrap_or(false)
- {
+ ) {
// not on a branch, we are either on a not-modified tag or some sort of detached head, so skip this
return Ok(None);
}
@@ -145,9 +141,7 @@ impl GitDownloader {
),
&refs,
Some(&mut m),
- )
- .unwrap_or(false)
- {
+ ) {
let matches: Vec<String> =
m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default();
for match_ in matches {
@@ -284,7 +278,7 @@ impl GitDownloader {
// If the non-existent branch is actually the name of a file, the file
// is checked out.
- let mut branch = Preg::replace(r"{(?:^dev-|(?:\.x)?-dev$)}i", "", &pretty_version)?;
+ let mut branch = Preg::replace(r"{(?:^dev-|(?:\.x)?-dev$)}i", "", &pretty_version);
// Closure equivalent: $execute = function(array $command) use (&$output, $path) { ... };
// Inlined below at each call site.
@@ -304,13 +298,12 @@ impl GitDownloader {
// check whether non-commitish are branches or tags, and fetch branches with the remote name
let git_ref = reference.to_string();
- if !Preg::is_match(r"{^[a-f0-9]{40}$}", reference).unwrap_or(false)
+ if !Preg::is_match(r"{^[a-f0-9]{40}$}", reference)
&& branches.is_some()
&& Preg::is_match(
&format!("{{^\\s+composer/{}$}}m", preg_quote(reference, None)),
branches.as_deref().unwrap_or(""),
)
- .unwrap_or(false)
{
let mut command1: Vec<String> = vec!["git".to_string(), "checkout".to_string()];
command1.extend(force.clone());
@@ -350,19 +343,17 @@ impl GitDownloader {
}
// try to checkout branch by name and then reset it so it's on the proper branch name
- if Preg::is_match(r"{^[a-f0-9]{40}$}", reference).unwrap_or(false) {
+ if Preg::is_match(r"{^[a-f0-9]{40}$}", reference) {
// add 'v' in front of the branch if it was stripped when generating the pretty name
if branches.is_some()
&& !Preg::is_match(
&format!("{{^\\s+composer/{}$}}m", preg_quote(&branch, None)),
branches.as_deref().unwrap_or(""),
)
- .unwrap_or(false)
&& Preg::is_match(
&format!("{{^\\s+composer/v{}$}}m", preg_quote(&branch, None)),
branches.as_deref().unwrap_or(""),
)
- .unwrap_or(false)
{
branch = format!("v{}", branch);
}
@@ -516,9 +507,7 @@ impl GitDownloader {
),
url,
Some(&mut match_),
- )
- .unwrap_or(false)
- {
+ ) {
let protocols = self.inner.config.borrow_mut().get("github-protocols");
let m1 = match_
.get(&CaptureKey::ByIndex(1))
@@ -672,9 +661,7 @@ impl GitDownloader {
}
pub(crate) fn get_short_hash(&self, reference: &str) -> String {
- if !self.inner.io.is_verbose()
- && Preg::is_match(r"{^[0-9a-f]{40}$}", reference).unwrap_or(false)
- {
+ if !self.inner.io.is_verbose() && Preg::is_match(r"{^[0-9a-f]{40}$}", reference) {
return substr(reference, 0, Some(10));
}
@@ -804,7 +791,7 @@ impl VcsDownloader for GitDownloader {
.get("cache-vcs-dir")
.as_string()
.unwrap_or(""),
- Preg::replace(r"{[^a-z0-9.]}i", "-", &Url::sanitize(url.to_string()))?,
+ Preg::replace(r"{[^a-z0-9.]}i", "-", &Url::sanitize(url.to_string())),
);
let git_version = GitUtil::get_version(&self.inner.process);
@@ -872,7 +859,7 @@ impl VcsDownloader for GitDownloader {
.get("cache-vcs-dir")
.as_string()
.unwrap_or(""),
- Preg::replace(r"{[^a-z0-9.]}i", "-", &Url::sanitize(url.to_string()))?,
+ Preg::replace(r"{[^a-z0-9.]}i", "-", &Url::sanitize(url.to_string())),
);
let r#ref = package.get_source_reference().unwrap_or_default();
@@ -1036,7 +1023,7 @@ impl VcsDownloader for GitDownloader {
.get("cache-vcs-dir")
.as_string()
.unwrap_or(""),
- Preg::replace(r"{[^a-z0-9.]}i", "-", &Url::sanitize(url.to_string()))?,
+ Preg::replace(r"{[^a-z0-9.]}i", "-", &Url::sanitize(url.to_string())),
);
let r#ref = target.get_source_reference().unwrap_or_default();
@@ -1142,15 +1129,11 @@ impl VcsDownloader for GitDownloader {
r"{^origin\s+(?P<url>\S+)}m",
&output,
Some(&mut origin_match),
- )
- .unwrap_or(false)
- && Preg::is_match3(
- r"{^composer\s+(?P<url>\S+)}m",
- &output,
- Some(&mut composer_match),
- )
- .unwrap_or(false)
- {
+ ) && Preg::is_match3(
+ r"{^composer\s+(?P<url>\S+)}m",
+ &output,
+ Some(&mut composer_match),
+ ) {
let origin_url = origin_match
.get(&CaptureKey::ByName("url".to_string()))
.cloned()
@@ -1229,7 +1212,7 @@ impl VcsDownloader for GitDownloader {
let changes: Vec<String> = array_map(
|elem: &String| format!(" {}", elem),
- &Preg::split(r"{\s*\r?\n\s*}", &changes)?,
+ &Preg::split(r"{\s*\r?\n\s*}", &changes),
);
self.inner.io.write_error3(
&format!(
diff --git a/crates/shirabe/src/downloader/svn_downloader.rs b/crates/shirabe/src/downloader/svn_downloader.rs
index e66d3ae..03fd292 100644
--- a/crates/shirabe/src/downloader/svn_downloader.rs
+++ b/crates/shirabe/src/downloader/svn_downloader.rs
@@ -281,7 +281,6 @@ impl VcsDownloader for SvnDownloader {
let changes_str = changes.unwrap();
let changes: Vec<String> = Preg::split(r"{\s*\r?\n\s*}", &changes_str)
- .unwrap_or_default()
.into_iter()
.map(|elem| format!(" {}", elem))
.collect();
@@ -367,8 +366,8 @@ impl VcsDownloader for SvnDownloader {
to_reference: &str,
path: &str,
) -> anyhow::Result<String> {
- if Preg::is_match(r"{@(\d+)$}", from_reference).unwrap_or(false)
- && Preg::is_match(r"{@(\d+)$}", to_reference).unwrap_or(false)
+ if Preg::is_match(r"{@(\d+)$}", from_reference)
+ && Preg::is_match(r"{@(\d+)$}", to_reference)
{
// retrieve the svn base url from the checkout folder
let command = vec![
@@ -399,25 +398,22 @@ impl VcsDownloader for SvnDownloader {
let url_pattern = "#<url>(.*)</url>#";
let mut matches: IndexMap<CaptureKey, String> = IndexMap::new();
- let base_url =
- if Preg::match3(url_pattern, &output, Some(&mut matches)).unwrap_or(false) {
- matches
- .get(&CaptureKey::ByIndex(1))
- .cloned()
- .unwrap_or_default()
- } else {
- return Err(RuntimeException {
- message: format!("Unable to determine svn url for path {}", path),
- code: 0,
- }
- .into());
- };
+ let base_url = if Preg::match3(url_pattern, &output, Some(&mut matches)) {
+ matches
+ .get(&CaptureKey::ByIndex(1))
+ .cloned()
+ .unwrap_or_default()
+ } else {
+ return Err(RuntimeException {
+ message: format!("Unable to determine svn url for path {}", path),
+ code: 0,
+ }
+ .into());
+ };
// strip paths from references and only keep the actual revision
- let from_revision =
- Preg::replace(r"{.*@(\d+)$}", "$1", &from_reference).unwrap_or_default();
- let to_revision =
- Preg::replace(r"{.*@(\d+)$}", "$1", &to_reference).unwrap_or_default();
+ let from_revision = Preg::replace(r"{.*@(\d+)$}", "$1", &from_reference);
+ let to_revision = Preg::replace(r"{.*@(\d+)$}", "$1", &to_reference);
let command = vec![
"svn".to_string(),
@@ -474,13 +470,11 @@ impl ChangeReportInterface for SvnDownloader {
Some(path.to_string()),
);
- Ok(
- if Preg::is_match("{^ *[^X ] +}m", &output).unwrap_or(false) {
- Some(output)
- } else {
- None
- },
- )
+ Ok(if Preg::is_match("{^ *[^X ] +}m", &output) {
+ Some(output)
+ } else {
+ None
+ })
}
}
diff --git a/crates/shirabe/src/downloader/zip_downloader.rs b/crates/shirabe/src/downloader/zip_downloader.rs
index 0613c15..d4ec2ab 100644
--- a/crates/shirabe/src/downloader/zip_downloader.rs
+++ b/crates/shirabe/src/downloader/zip_downloader.rs
@@ -116,9 +116,7 @@ impl ZipDownloader {
== 0
{
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3(r"^\s*7-Zip(?:\s\[64\])?\s([0-9.]+)", &output, Some(&mut m))
- .unwrap_or(false)
- {
+ if Preg::is_match3(r"^\s*7-Zip(?:\s\[64\])?\s([0-9.]+)", &output, Some(&mut m)) {
let m1 = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default();
if version_compare(&m1, "21.01", "<") {
self.inner.io.write_error(&format!(