diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-29 00:03:00 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-29 00:03:00 +0900 |
| commit | 9be0f98f71fe8071ab839ac1036b4064ac3172b4 (patch) | |
| tree | 66a2f4feba752f4761c40449e0827ad74fc9b02c /crates/shirabe/src/util | |
| parent | a84d531548efa678d4021cea891826e59f8fb462 (diff) | |
| download | php-shirabe-9be0f98f71fe8071ab839ac1036b4064ac3172b4.tar.gz php-shirabe-9be0f98f71fe8071ab839ac1036b4064ac3172b4.tar.zst php-shirabe-9be0f98f71fe8071ab839ac1036b4064ac3172b4.zip | |
chore(lint): ban bare `use anyhow::Result` and fully qualify it
Add a no_banned_use linter that forbids importing anyhow::Result, and
update all call sites to reference it via its fully-qualified path so
it is never confused with std::result::Result.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/util')
| -rw-r--r-- | crates/shirabe/src/util/auth_helper.rs | 7 | ||||
| -rw-r--r-- | crates/shirabe/src/util/forgejo_url.rs | 3 | ||||
| -rw-r--r-- | crates/shirabe/src/util/git.rs | 21 | ||||
| -rw-r--r-- | crates/shirabe/src/util/hg.rs | 5 | ||||
| -rw-r--r-- | crates/shirabe/src/util/http_downloader.rs | 29 | ||||
| -rw-r--r-- | crates/shirabe/src/util/loop.rs | 7 | ||||
| -rw-r--r-- | crates/shirabe/src/util/no_proxy_pattern.rs | 22 | ||||
| -rw-r--r-- | crates/shirabe/src/util/perforce.rs | 35 | ||||
| -rw-r--r-- | crates/shirabe/src/util/platform.rs | 7 | ||||
| -rw-r--r-- | crates/shirabe/src/util/process_executor.rs | 46 | ||||
| -rw-r--r-- | crates/shirabe/src/util/silencer.rs | 5 | ||||
| -rw-r--r-- | crates/shirabe/src/util/svn.rs | 13 | ||||
| -rw-r--r-- | crates/shirabe/src/util/sync_helper.rs | 21 | ||||
| -rw-r--r-- | crates/shirabe/src/util/tar.rs | 5 | ||||
| -rw-r--r-- | crates/shirabe/src/util/zip.rs | 5 |
15 files changed, 119 insertions, 112 deletions
diff --git a/crates/shirabe/src/util/auth_helper.rs b/crates/shirabe/src/util/auth_helper.rs index 8a89842..13199e9 100644 --- a/crates/shirabe/src/util/auth_helper.rs +++ b/crates/shirabe/src/util/auth_helper.rs @@ -8,7 +8,6 @@ use crate::io::io_interface; use crate::util::Bitbucket; use crate::util::GitHub; use crate::util::GitLab; -use anyhow::Result; use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::Preg; use shirabe_php_shim::{ @@ -54,7 +53,7 @@ impl AuthHelper { } /// @param 'prompt'|bool $storeAuth - pub fn store_auth(&self, origin: &str, store_auth: StoreAuth) -> Result<()> { + pub fn store_auth(&self, origin: &str, store_auth: StoreAuth) -> anyhow::Result<()> { let mut store: Option<()> = None; let mut config = self.config.borrow_mut(); let config_source = config.get_auth_config_source_mut(); @@ -123,7 +122,7 @@ impl AuthHelper { headers: Vec<String>, retry_count: i64, response_body: Option<&str>, - ) -> Result<PromptAuthResult> { + ) -> anyhow::Result<PromptAuthResult> { let mut store_auth: StoreAuth = StoreAuth::Bool(false); let github_domains = self.config.borrow_mut().get("github-domains"); @@ -450,7 +449,7 @@ impl AuthHelper { mut options: IndexMap<String, PhpMixed>, origin: &str, url: &str, - ) -> Result<IndexMap<String, PhpMixed>> { + ) -> anyhow::Result<IndexMap<String, PhpMixed>> { if !options.contains_key("http") { options.insert("http".to_string(), PhpMixed::Array(IndexMap::new())); } diff --git a/crates/shirabe/src/util/forgejo_url.rs b/crates/shirabe/src/util/forgejo_url.rs index d336b87..157ea53 100644 --- a/crates/shirabe/src/util/forgejo_url.rs +++ b/crates/shirabe/src/util/forgejo_url.rs @@ -1,6 +1,5 @@ //! ref: composer/src/Composer/Util/ForgejoUrl.php -use anyhow::Result; use shirabe_external_packages::composer::pcre::Preg; use shirabe_php_shim::InvalidArgumentException; @@ -25,7 +24,7 @@ impl ForgejoUrl { } } - pub fn create(repo_url: &str) -> Result<Self> { + pub fn create(repo_url: &str) -> anyhow::Result<Self> { match Self::try_from(Some(repo_url)) { Some(url) => Ok(url), None => Err(InvalidArgumentException { diff --git a/crates/shirabe/src/util/git.rs b/crates/shirabe/src/util/git.rs index ee9f9e6..bd7b13b 100644 --- a/crates/shirabe/src/util/git.rs +++ b/crates/shirabe/src/util/git.rs @@ -13,7 +13,6 @@ use crate::util::Platform; use crate::util::ProcessExecutor; use crate::util::Url; use crate::util::{AuthHelper, StoreAuth}; -use anyhow::Result; use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::{CaptureKey, Preg}; use shirabe_php_shim::{ @@ -56,7 +55,7 @@ impl Git { output: &str, path: &str, io: Option<std::rc::Rc<std::cell::RefCell<dyn IOInterface>>>, - ) -> Result<()> { + ) -> anyhow::Result<()> { if str_contains(output, "fatal: detected dubious ownership") { let msg = format!( "The repository at \"{}\" does not have the correct ownership and git refuses to use it:{}{}{}", @@ -106,7 +105,7 @@ impl Git { cwd: Option<&str>, initial_clone: bool, command_output: Option<&mut PhpMixed>, - ) -> Result<()> { + ) -> anyhow::Result<()> { let mut callables: Vec<Box<dyn Fn(&str) -> Vec<String>>> = vec![]; for cmd in commands { let cmd_clone = cmd.clone(); @@ -138,7 +137,7 @@ impl Git { cwd: Option<&str>, initial_clone: bool, command_output: Option<&mut PhpMixed>, - ) -> Result<()> { + ) -> anyhow::Result<()> { self.run_command(command_callable, url, cwd, initial_clone, command_output) } @@ -152,7 +151,7 @@ impl Git { cwd: Option<&str>, initial_clone: bool, mut command_output: Option<&mut PhpMixed>, - ) -> Result<()> { + ) -> anyhow::Result<()> { let command_callables = command_callable; let mut last_command: PhpMixed = PhpMixed::String(String::new()); @@ -786,7 +785,7 @@ impl Git { Ok(()) } - pub fn sync_mirror(&mut self, url: &str, dir: &str) -> Result<bool> { + pub fn sync_mirror(&mut self, url: &str, dir: &str) -> anyhow::Result<bool> { let composer_disable_network = Platform::get_env("COMPOSER_DISABLE_NETWORK"); if composer_disable_network .as_ref() @@ -821,7 +820,7 @@ impl Git { && trim(&output, None) == "." { // PHP try/finally - let try_result: Result<()> = (|| -> Result<()> { + let try_result: anyhow::Result<()> = (|| -> anyhow::Result<()> { let commands = vec![ vec![ "git".to_string(), @@ -917,7 +916,7 @@ impl Git { dir: &str, r#ref: &str, pretty_version: Option<&str>, - ) -> Result<bool> { + ) -> anyhow::Result<bool> { if self.check_ref_is_in_mirror(dir, r#ref)? { if Preg::is_match(r"{^[a-f0-9]{40}$}", r#ref) && let Some(pretty_version) = pretty_version @@ -1048,7 +1047,7 @@ impl Git { Preg::replace(r"{^commit [a-f0-9]{40}\n?}m", "", output) } - fn check_ref_is_in_mirror(&mut self, dir: &str, r#ref: &str) -> Result<bool> { + fn check_ref_is_in_mirror(&mut self, dir: &str, r#ref: &str) -> anyhow::Result<bool> { let mut output = String::new(); if is_dir(dir) && self.process.borrow_mut().execute_args( @@ -1121,7 +1120,7 @@ impl Git { return None; } - let result: Result<Option<String>> = (|| -> Result<Option<String>> { + let result: anyhow::Result<Option<String>> = (|| -> anyhow::Result<Option<String>> { let mut output_mixed = PhpMixed::Null; if is_local_path_repository { let mut output = String::new(); @@ -1262,7 +1261,7 @@ impl Git { /// @param non-empty-string $message /// /// @return never - fn throw_exception(&mut self, message: &str, url: &str) -> Result<()> { + fn throw_exception(&mut self, message: &str, url: &str) -> anyhow::Result<()> { // git might delete a directory when it fails and php will not know clearstatcache(); diff --git a/crates/shirabe/src/util/hg.rs b/crates/shirabe/src/util/hg.rs index cdfcd4e..56e5044 100644 --- a/crates/shirabe/src/util/hg.rs +++ b/crates/shirabe/src/util/hg.rs @@ -5,7 +5,6 @@ use crate::io::IOInterface; use crate::io::IOInterfaceImmutable; use crate::util::ProcessExecutor; use crate::util::Url; -use anyhow::Result; use shirabe_external_packages::composer::pcre::Preg; use shirabe_php_shim::rawurlencode; use std::sync::OnceLock; @@ -37,7 +36,7 @@ impl Hg { command_callable: impl Fn(String) -> Vec<String>, url: String, cwd: Option<String>, - ) -> Result<()> { + ) -> anyhow::Result<()> { self.config.borrow_mut().prohibit_url_by_config( &url, Some(self.io.clone()), @@ -126,7 +125,7 @@ impl Hg { self.throw_exception(&format!("Failed to clone {}, \n\n{}", url, error), &url) } - fn throw_exception(&self, message: &str, url: &str) -> Result<()> { + fn throw_exception(&self, message: &str, url: &str) -> anyhow::Result<()> { if Self::get_version(&self.process).is_none() { anyhow::bail!( "{}", diff --git a/crates/shirabe/src/util/http_downloader.rs b/crates/shirabe/src/util/http_downloader.rs index 18e320c..eeb4b6f 100644 --- a/crates/shirabe/src/util/http_downloader.rs +++ b/crates/shirabe/src/util/http_downloader.rs @@ -14,7 +14,6 @@ use crate::util::StreamContextFactory; use crate::util::Url; use crate::util::http::CurlDownloader; use crate::util::http::Response; -use anyhow::Result; use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::{CaptureKey, Preg}; use shirabe_php_shim::{ @@ -215,7 +214,11 @@ impl HttpDownloader { } /// Download a file synchronously - pub fn get(&mut self, url: &str, options: IndexMap<String, PhpMixed>) -> Result<Response> { + pub fn get( + &mut self, + url: &str, + options: IndexMap<String, PhpMixed>, + ) -> anyhow::Result<Response> { if self.mock.is_some() { return self.mock_get(url, &options); } @@ -246,7 +249,7 @@ impl HttpDownloader { &mut self, url: &str, options: IndexMap<String, PhpMixed>, - ) -> Result<Response> { + ) -> anyhow::Result<Response> { if self.mock.is_some() { return self.mock_get(url, &options); } @@ -276,7 +279,7 @@ impl HttpDownloader { url: &str, to: &str, options: IndexMap<String, PhpMixed>, - ) -> Result<Response> { + ) -> anyhow::Result<Response> { if self.mock.is_some() { return self.mock_get(url, &options); } @@ -306,7 +309,7 @@ impl HttpDownloader { url: &str, to: &str, options: IndexMap<String, PhpMixed>, - ) -> Result<Response> { + ) -> anyhow::Result<Response> { if self.mock.is_some() { return self.mock_get(url, &options); } @@ -345,7 +348,7 @@ impl HttpDownloader { /// Queues a job and starts it if there is capacity. Mirrors PHP `addJob`: for non-curl (rfs) /// jobs the work runs synchronously here (PHP runs it in the Promise resolver during /// construction); for curl jobs the work is driven later by `start_job` / `count_active_jobs`. - fn add_job(&mut self, mut request: Request, sync: bool) -> Result<JobHandle> { + fn add_job(&mut self, mut request: Request, sync: bool) -> anyhow::Result<JobHandle> { request.options = array_replace_recursive(self.options.clone(), request.options); let id = self.id_gen; @@ -593,11 +596,11 @@ impl HttpDownloader { /// Wait for current async download jobs to complete /// /// @param int|null $index For internal use only, the job id - pub fn wait(&mut self) -> Result<()> { + pub fn wait(&mut self) -> anyhow::Result<()> { self.wait_id(None) } - fn wait_id(&mut self, index: Option<i64>) -> Result<()> { + fn wait_id(&mut self, index: Option<i64>) -> anyhow::Result<()> { loop { let job_count = self.count_active_jobs(index)?; if job_count == 0 { @@ -613,7 +616,7 @@ impl HttpDownloader { } /// @internal - pub fn count_active_jobs(&mut self, index: Option<i64>) -> Result<i64> { + pub fn count_active_jobs(&mut self, index: Option<i64>) -> anyhow::Result<i64> { if self.running_jobs < self.max_jobs { let queued_ids: Vec<i64> = self .jobs @@ -676,7 +679,7 @@ impl HttpDownloader { } /// @param int $index Job id - fn get_response(&mut self, index: i64) -> Result<Response> { + fn get_response(&mut self, index: i64) -> anyhow::Result<Response> { if !self.jobs.contains_key(&index) { return Err(LogicException { message: "Invalid request id".to_string(), @@ -712,7 +715,7 @@ impl HttpDownloader { io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, url: &str, data: &IndexMap<String, PhpMixed>, - ) -> Result<()> { + ) -> anyhow::Result<()> { let clean_message = |msg: &str| -> anyhow::Result<String> { if !io.is_decorated() { return Ok(Preg::replace( @@ -949,7 +952,7 @@ impl HttpDownloader { &mut self, file_url: &str, options: &IndexMap<String, PhpMixed>, - ) -> Result<Response> { + ) -> anyhow::Result<Response> { if file_url.is_empty() { return Err(LogicException { message: "url cannot be an empty string".to_string(), @@ -1019,7 +1022,7 @@ impl HttpDownloader { status: i64, headers: Vec<String>, body: String, - ) -> Result<Response> { + ) -> anyhow::Result<Response> { if status < 400 { return Ok(Response::new( url.to_string(), diff --git a/crates/shirabe/src/util/loop.rs b/crates/shirabe/src/util/loop.rs index 2a0e6d3..4efd770 100644 --- a/crates/shirabe/src/util/loop.rs +++ b/crates/shirabe/src/util/loop.rs @@ -2,7 +2,6 @@ use crate::util::HttpDownloader; use crate::util::ProcessExecutor; -use anyhow::Result; use shirabe_external_packages::symfony::console::helper::ProgressBar; #[derive(Debug)] @@ -40,9 +39,11 @@ impl Loop { pub async fn wait<'p>( &mut self, - promises: Vec<std::pin::Pin<Box<dyn std::future::Future<Output = Result<()>> + 'p>>>, + promises: Vec< + std::pin::Pin<Box<dyn std::future::Future<Output = anyhow::Result<()>> + 'p>>, + >, _progress: Option<&mut ProgressBar>, - ) -> Result<()> { + ) -> anyhow::Result<()> { let mut uncaught: Option<anyhow::Error> = None; // TODO(phase-c-promise): the asynchronous worker classes (HttpDownloader / ProcessExecutor) diff --git a/crates/shirabe/src/util/no_proxy_pattern.rs b/crates/shirabe/src/util/no_proxy_pattern.rs index 3715ea9..0a3d564 100644 --- a/crates/shirabe/src/util/no_proxy_pattern.rs +++ b/crates/shirabe/src/util/no_proxy_pattern.rs @@ -1,6 +1,5 @@ //! ref: composer/src/Composer/Util/NoProxyPattern.php -use anyhow::Result; use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::Preg; use shirabe_php_shim::{ @@ -49,7 +48,7 @@ impl NoProxyPattern { } /// Returns true if a URL matches the NO_PROXY pattern - pub fn test(&mut self, url: &str) -> Result<bool> { + pub fn test(&mut self, url: &str) -> anyhow::Result<bool> { if self.noproxy { return Ok(true); } @@ -72,7 +71,7 @@ impl NoProxyPattern { /// Returns false is the url cannot be parsed, otherwise a data object /// /// @return bool|stdClass - pub(crate) fn get_url_data(&self, url: &str) -> Result<Option<UrlData>> { + pub(crate) fn get_url_data(&self, url: &str) -> anyhow::Result<Option<UrlData>> { let host = parse_url(url, PHP_URL_HOST); if empty(&host) { return Ok(None); @@ -110,7 +109,12 @@ impl NoProxyPattern { } /// Returns true if the url is matched by a rule - pub(crate) fn r#match(&mut self, index: i64, host_name: &str, url: &UrlData) -> Result<bool> { + pub(crate) fn r#match( + &mut self, + index: i64, + host_name: &str, + url: &UrlData, + ) -> anyhow::Result<bool> { let rule = match self.get_rule(index, host_name)? { Some(r) => r, None => { @@ -146,7 +150,7 @@ impl NoProxyPattern { } /// Returns true if the target ip is in the network range - pub(crate) fn match_range(&self, network: &IpData, target: &IpData) -> Result<bool> { + pub(crate) fn match_range(&self, network: &IpData, target: &IpData) -> anyhow::Result<bool> { let net = unpack("C*", &network.ip); let mask = unpack("C*", network.netmask.as_deref().unwrap_or_default()); let ip = unpack("C*", &target.ip); @@ -212,7 +216,7 @@ impl NoProxyPattern { /// Finds or creates rule data for a hostname /// /// @return null|stdClass Null if the hostname is invalid - fn get_rule(&mut self, index: i64, host_name: &str) -> Result<Option<UrlData>> { + fn get_rule(&mut self, index: i64, host_name: &str) -> anyhow::Result<Option<UrlData>> { if array_key_exists(&index.to_string(), &{ let mut m: IndexMap<String, ()> = IndexMap::new(); for k in self.rules.keys() { @@ -248,7 +252,7 @@ impl NoProxyPattern { host: &str, ipdata: &mut Option<IpData>, allow_prefix: bool, - ) -> Result<bool> { + ) -> anyhow::Result<bool> { *ipdata = None; let mut netmask: Option<Vec<u8>> = None; let mut prefix: Option<i64> = None; @@ -345,7 +349,7 @@ impl NoProxyPattern { range_ip: &[u8], size: i64, prefix: i64, - ) -> Result<(Vec<u8>, Vec<u8>)> { + ) -> anyhow::Result<(Vec<u8>, Vec<u8>)> { let netmask = self.ip_get_mask(prefix, size); // Get the network from the address and mask @@ -435,7 +439,7 @@ impl NoProxyPattern { /// Splits the hostname into host and port components /// /// @return mixed[] host, port, if there was error - fn split_host_port(&self, host_name: &str) -> Result<(String, i64, bool)> { + fn split_host_port(&self, host_name: &str) -> anyhow::Result<(String, i64, bool)> { // host, port, err let error = (String::new(), 0_i64, true); let mut port: i64 = 0; diff --git a/crates/shirabe/src/util/perforce.rs b/crates/shirabe/src/util/perforce.rs index bd8e9e6..389618e 100644 --- a/crates/shirabe/src/util/perforce.rs +++ b/crates/shirabe/src/util/perforce.rs @@ -5,7 +5,6 @@ use crate::io::IOInterfaceImmutable; use crate::util::Filesystem; use crate::util::Platform; use crate::util::ProcessExecutor; -use anyhow::Result; use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::Preg; use shirabe_external_packages::symfony::process::ExecutableFinder; @@ -351,7 +350,7 @@ impl Perforce { result } - pub fn is_logged_in(&mut self) -> Result<bool> { + pub fn is_logged_in(&mut self) -> anyhow::Result<bool> { let command = self.generate_p4_command(vec!["login".to_string(), "-s".to_string()], false); let exit_code = self.execute_command(PhpMixed::List( command.into_iter().map(PhpMixed::String).collect(), @@ -381,7 +380,7 @@ impl Perforce { Ok(true) } - pub fn connect_client(&mut self) -> Result<()> { + pub fn connect_client(&mut self) -> anyhow::Result<()> { let p4_create_client_command = self.generate_p4_command(vec!["client".to_string(), "-i".to_string()], true); @@ -398,7 +397,7 @@ impl Perforce { Ok(()) } - pub fn sync_code_base(&mut self, source_reference: Option<&str>) -> Result<()> { + pub fn sync_code_base(&mut self, source_reference: Option<&str>) -> anyhow::Result<()> { let prev_dir = Platform::get_cwd(false)?; chdir(&self.path); let mut p4_sync_command = @@ -503,7 +502,7 @@ impl Perforce { } } - pub fn write_p4_client_spec(&mut self) -> Result<()> { + pub fn write_p4_client_spec(&mut self) -> anyhow::Result<()> { let client_spec = self.get_p4_client_spec(); let spec = match fopen(&client_spec, "w") { Ok(spec) => spec, @@ -542,7 +541,7 @@ impl Perforce { } } - pub fn windows_login(&mut self, password: Option<&str>) -> Result<i64> { + pub fn windows_login(&mut self, password: Option<&str>) -> anyhow::Result<i64> { let command = self.generate_p4_command(vec!["login".to_string(), "-a".to_string()], true); let mut process = Process::new( @@ -558,7 +557,7 @@ impl Perforce { process.run(None, indexmap::IndexMap::new()) } - pub fn p4_login(&mut self) -> Result<()> { + pub fn p4_login(&mut self) -> anyhow::Result<()> { self.query_p4_user(); if !self.is_logged_in()? { let password = self.query_p4_password(); @@ -597,7 +596,7 @@ impl Perforce { pub fn get_composer_information( &mut self, identifier: &str, - ) -> Result<Option<IndexMap<String, PhpMixed>>> { + ) -> anyhow::Result<Option<IndexMap<String, PhpMixed>>> { let composer_file_content = self.get_file_content("composer.json", identifier); let composer_file_content = match composer_file_content { @@ -842,11 +841,11 @@ impl Perforce { pub trait PerforceInterface: std::fmt::Debug { fn initialize_path(&mut self, path: &str); fn set_stream(&mut self, stream: &str); - fn p4_login(&mut self) -> Result<()>; + fn p4_login(&mut self) -> anyhow::Result<()>; fn check_stream(&mut self) -> bool; - fn write_p4_client_spec(&mut self) -> Result<()>; - fn connect_client(&mut self) -> Result<()>; - fn sync_code_base(&mut self, source_reference: Option<String>) -> Result<()>; + fn write_p4_client_spec(&mut self) -> anyhow::Result<()>; + fn connect_client(&mut self) -> anyhow::Result<()>; + fn sync_code_base(&mut self, source_reference: Option<String>) -> anyhow::Result<()>; fn cleanup_client_spec(&mut self); fn get_commit_logs(&mut self, from_reference: &str, to_reference: &str) -> Option<String>; fn get_file_content(&mut self, file: &str, identifier: &str) -> Option<String>; @@ -856,7 +855,7 @@ pub trait PerforceInterface: std::fmt::Debug { fn get_composer_information( &mut self, identifier: &str, - ) -> Result<Option<IndexMap<String, PhpMixed>>>; + ) -> anyhow::Result<Option<IndexMap<String, PhpMixed>>>; } impl PerforceInterface for Perforce { @@ -868,7 +867,7 @@ impl PerforceInterface for Perforce { Perforce::set_stream(self, stream) } - fn p4_login(&mut self) -> Result<()> { + fn p4_login(&mut self) -> anyhow::Result<()> { Perforce::p4_login(self) } @@ -876,15 +875,15 @@ impl PerforceInterface for Perforce { Perforce::check_stream(self) } - fn write_p4_client_spec(&mut self) -> Result<()> { + fn write_p4_client_spec(&mut self) -> anyhow::Result<()> { Perforce::write_p4_client_spec(self) } - fn connect_client(&mut self) -> Result<()> { + fn connect_client(&mut self) -> anyhow::Result<()> { Perforce::connect_client(self) } - fn sync_code_base(&mut self, source_reference: Option<String>) -> Result<()> { + fn sync_code_base(&mut self, source_reference: Option<String>) -> anyhow::Result<()> { Perforce::sync_code_base(self, source_reference.as_deref()) } @@ -915,7 +914,7 @@ impl PerforceInterface for Perforce { fn get_composer_information( &mut self, identifier: &str, - ) -> Result<Option<IndexMap<String, PhpMixed>>> { + ) -> anyhow::Result<Option<IndexMap<String, PhpMixed>>> { Perforce::get_composer_information(self, identifier) } } diff --git a/crates/shirabe/src/util/platform.rs b/crates/shirabe/src/util/platform.rs index b3b7e2b..45ddb30 100644 --- a/crates/shirabe/src/util/platform.rs +++ b/crates/shirabe/src/util/platform.rs @@ -2,7 +2,6 @@ use crate::util::ProcessExecutor; use crate::util::Silencer; -use anyhow::Result; use shirabe_external_packages::composer::pcre::Preg; use shirabe_php_shim::{ PHP_ENV, PHP_SERVER, PhpMixed, PhpResource, RuntimeException, defined, file_exists, @@ -24,7 +23,7 @@ impl Platform { /// getcwd() equivalent which always returns a string /// /// @throws \RuntimeException - pub fn get_cwd(allow_empty: bool) -> Result<String> { + pub fn get_cwd(allow_empty: bool) -> anyhow::Result<String> { let mut cwd = getcwd(); // fallback to realpath('') just in case this works but odds are it would break as well if we are in a case where getcwd fails @@ -144,7 +143,7 @@ impl Platform { /// @throws \RuntimeException If the user home could not reliably be determined /// @return string The formal user home as detected from environment parameters - pub fn get_user_directory() -> Result<String> { + pub fn get_user_directory() -> anyhow::Result<String> { if let Some(home) = Self::get_env("HOME") { return Ok(home); } @@ -378,7 +377,7 @@ impl Platform { if php_os_family() == "Linux" { let mut process = ProcessExecutor::new(None); let mut output = String::new(); - let result: Result<()> = (|| { + let result: anyhow::Result<()> = (|| { if process.execute_args(&["lsmod".to_string()], &mut output, None) == 0 && shirabe_php_shim::str_contains(&output, "vboxguest") { diff --git a/crates/shirabe/src/util/process_executor.rs b/crates/shirabe/src/util/process_executor.rs index 230695a..463e511 100644 --- a/crates/shirabe/src/util/process_executor.rs +++ b/crates/shirabe/src/util/process_executor.rs @@ -5,7 +5,6 @@ use crate::io::IOInterfaceImmutable; use crate::io::io_interface; use crate::util::GitHub; use crate::util::Platform; -use anyhow::Result; use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::{CaptureKey, Preg}; use shirabe_external_packages::seld::signal::SignalHandler; @@ -170,7 +169,12 @@ impl ProcessExecutor { } /// runs a process on the commandline - pub fn execute<'o, C, O>(&mut self, command: C, output: O, cwd: Option<&str>) -> Result<i64> + pub fn execute<'o, C, O>( + &mut self, + command: C, + output: O, + cwd: Option<&str>, + ) -> anyhow::Result<i64> where C: IntoExecCommand, O: IntoExecOutput<'o>, @@ -201,7 +205,7 @@ impl ProcessExecutor { } /// runs a process on the commandline in TTY mode - pub fn execute_tty<C>(&mut self, command: C, cwd: Option<&str>) -> Result<i64> + pub fn execute_tty<C>(&mut self, command: C, cwd: Option<&str>) -> anyhow::Result<i64> where C: IntoExecCommand, { @@ -220,7 +224,7 @@ impl ProcessExecutor { env: Option<IndexMap<String, String>>, tty: bool, output: O, - ) -> Result<Option<i64>> + ) -> anyhow::Result<Option<i64>> where O: IntoExecOutput<'o>, { @@ -302,7 +306,7 @@ impl ProcessExecutor { }), ); - let result: Result<()> = (|| -> Result<()> { + let result: anyhow::Result<()> = (|| -> anyhow::Result<()> { match output.to_callback() { Ok(callback) => { process.run(Some(callback), IndexMap::new())?; @@ -324,7 +328,7 @@ impl ProcessExecutor { self.error_output = process.get_error_output()?; Ok(()) })(); - let final_result: Result<()> = match result { + let final_result: anyhow::Result<()> = match result { Ok(()) => Ok(()), Err(e) => { if let Some(pse) = e.downcast_ref::<ProcessSignaledException>() { @@ -352,7 +356,7 @@ impl ProcessExecutor { cwd: Option<&str>, tty: bool, output: O, - ) -> Result<i64> + ) -> anyhow::Result<i64> where O: IntoExecOutput<'o>, { @@ -409,7 +413,7 @@ impl ProcessExecutor { command: PhpMixed, cwd: Option<&str>, output: O, - ) -> Result<i64> + ) -> anyhow::Result<i64> where O: IntoExecOutput<'o>, { @@ -574,7 +578,11 @@ impl ProcessExecutor { } /// starts a process on the commandline in async mode - pub async fn execute_async<C>(&mut self, command: C, cwd: Option<&str>) -> Result<Process> + pub async fn execute_async<C>( + &mut self, + command: C, + cwd: Option<&str>, + ) -> anyhow::Result<Process> where C: IntoExecCommand, { @@ -677,7 +685,7 @@ impl ProcessExecutor { self.output_command_run(&command, cwd.as_deref(), true); - let process_result: Result<Process> = if is_string(&command) { + let process_result: anyhow::Result<Process> = if is_string(&command) { Process::from_shell_commandline( command.as_string().unwrap_or(""), cwd.as_deref(), @@ -760,11 +768,11 @@ impl ProcessExecutor { } /// @param ?int $index job id - pub fn wait(&mut self) -> Result<()> { + pub fn wait(&mut self) -> anyhow::Result<()> { self.wait_id(None) } - pub fn wait_id(&mut self, index: Option<i64>) -> Result<()> { + pub fn wait_id(&mut self, index: Option<i64>) -> anyhow::Result<()> { loop { if 0 == self.count_active_jobs(index)? { return Ok(()); @@ -780,7 +788,7 @@ impl ProcessExecutor { } /// @internal - pub fn count_active_jobs(&mut self, index: Option<i64>) -> Result<i64> { + pub fn count_active_jobs(&mut self, index: Option<i64>) -> anyhow::Result<i64> { // tick let ids: Vec<i64> = self.jobs.keys().copied().collect(); for id in &ids { @@ -1152,7 +1160,7 @@ pub trait IntoExecOutput<'a>: Sized { /// `Ok(callback)` for a user-supplied output handler (passed straight to `Process::run`), /// `Err(self)` for the capture/forward cases (a default handler is used and `self` is returned /// so the captured output can still be written back). - fn to_callback(self) -> Result<Box<dyn FnMut(&str, &str) -> bool>, Self>; + fn to_callback(self) -> anyhow::Result<Box<dyn FnMut(&str, &str) -> bool>, Self>; /// Assigns the captured output back to the by-reference target, mirroring PHP's /// `$output = $process->getOutput()`. Only meaningful when [`capture_output`](Self::capture_output) @@ -1167,7 +1175,7 @@ impl<'a> IntoExecOutput<'a> for () { true } - fn to_callback(self) -> Result<Box<dyn FnMut(&str, &str) -> bool>, Self> { + fn to_callback(self) -> anyhow::Result<Box<dyn FnMut(&str, &str) -> bool>, Self> { Err(self) } @@ -1181,7 +1189,7 @@ impl<'a> IntoExecOutput<'a> for ProcessForwardOutput { false } - fn to_callback(self) -> Result<Box<dyn FnMut(&str, &str) -> bool>, Self> { + fn to_callback(self) -> anyhow::Result<Box<dyn FnMut(&str, &str) -> bool>, Self> { Err(self) } @@ -1195,7 +1203,7 @@ impl<'a> IntoExecOutput<'a> for &'a mut PhpMixed { true } - fn to_callback(self) -> Result<Box<dyn FnMut(&str, &str) -> bool>, Self> { + fn to_callback(self) -> anyhow::Result<Box<dyn FnMut(&str, &str) -> bool>, Self> { Err(self) } @@ -1211,7 +1219,7 @@ impl<'a> IntoExecOutput<'a> for &'a mut String { true } - fn to_callback(self) -> Result<Box<dyn FnMut(&str, &str) -> bool>, Self> { + fn to_callback(self) -> anyhow::Result<Box<dyn FnMut(&str, &str) -> bool>, Self> { Err(self) } @@ -1228,7 +1236,7 @@ impl<'a> IntoExecOutput<'a> for Box<dyn FnMut(&str, &str) -> bool> { false } - fn to_callback(self) -> Result<Box<dyn FnMut(&str, &str) -> bool>, Self> { + fn to_callback(self) -> anyhow::Result<Box<dyn FnMut(&str, &str) -> bool>, Self> { Ok(self) } diff --git a/crates/shirabe/src/util/silencer.rs b/crates/shirabe/src/util/silencer.rs index f5ee64d..7286689 100644 --- a/crates/shirabe/src/util/silencer.rs +++ b/crates/shirabe/src/util/silencer.rs @@ -1,6 +1,5 @@ //! ref: composer/src/Composer/Util/Silencer.php -use anyhow::Result; use shirabe_php_shim::{ E_DEPRECATED, E_NOTICE, E_USER_DEPRECATED, E_USER_NOTICE, E_USER_WARNING, E_WARNING, error_reporting, @@ -36,9 +35,9 @@ impl Silencer { } } - pub fn call<F, T>(callable: F) -> Result<T> + pub fn call<F, T>(callable: F) -> anyhow::Result<T> where - F: FnOnce() -> Result<T>, + F: FnOnce() -> anyhow::Result<T>, { Self::suppress(None); match callable() { diff --git a/crates/shirabe/src/util/svn.rs b/crates/shirabe/src/util/svn.rs index 5eed44d..4c01a3a 100644 --- a/crates/shirabe/src/util/svn.rs +++ b/crates/shirabe/src/util/svn.rs @@ -6,7 +6,6 @@ use crate::io::IOInterfaceImmutable; use crate::io::io_interface; use crate::util::Platform; use crate::util::ProcessExecutor; -use anyhow::Result; use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::{CaptureKey, Preg}; use shirabe_php_shim::{ @@ -92,7 +91,7 @@ impl Svn { cwd: Option<&str>, path: Option<&str>, verbose: bool, - ) -> Result<String> { + ) -> anyhow::Result<String> { // Ensure we are allowed to use this URL by config self.config.borrow_mut().prohibit_url_by_config( url, @@ -119,7 +118,7 @@ impl Svn { path: &str, cwd: Option<&str>, verbose: bool, - ) -> Result<String> { + ) -> anyhow::Result<String> { // A local command has no remote url self.execute_with_auth_retry(command, cwd, "", Some(path), verbose) .map(|o| o.unwrap_or_default()) @@ -133,7 +132,7 @@ impl Svn { url: &str, path: Option<&str>, verbose: bool, - ) -> Result<Option<String>> { + ) -> anyhow::Result<Option<String>> { // Regenerate the command at each try, to use the newly user-provided credentials let command = self.get_command(svn_command.clone(), url, path); @@ -212,7 +211,7 @@ impl Svn { /// Repositories requests credentials, let's put them in. /// /// @throws \RuntimeException - pub(crate) fn do_auth_dance(&mut self) -> Result<&mut Self> { + pub(crate) fn do_auth_dance(&mut self) -> anyhow::Result<&mut Self> { // cannot ask for credentials in non interactive mode if !self.io.is_interactive() { return Err(RuntimeException { @@ -314,7 +313,7 @@ impl Svn { /// Get the password for the svn command. Can be empty. /// /// @throws \LogicException - pub(crate) fn get_password(&self) -> Result<String> { + pub(crate) fn get_password(&self) -> anyhow::Result<String> { if self.credentials.is_none() { return Err(LogicException { message: "No svn auth detected.".to_string(), @@ -329,7 +328,7 @@ impl Svn { /// Get the username for the svn command. /// /// @throws \LogicException - pub(crate) fn get_username(&self) -> Result<String> { + pub(crate) fn get_username(&self) -> anyhow::Result<String> { if self.credentials.is_none() { return Err(LogicException { message: "No svn auth detected.".to_string(), diff --git a/crates/shirabe/src/util/sync_helper.rs b/crates/shirabe/src/util/sync_helper.rs index 1014b86..68267ec 100644 --- a/crates/shirabe/src/util/sync_helper.rs +++ b/crates/shirabe/src/util/sync_helper.rs @@ -4,7 +4,6 @@ use crate::downloader::DownloadManagerInterface; use crate::downloader::DownloaderInterface; use crate::package::PackageInterfaceHandle; use crate::util::r#loop::Loop; -use anyhow::Result; use shirabe_php_shim::PhpMixed; pub enum DownloaderOrManager<'a> { @@ -18,7 +17,7 @@ impl<'a> DownloaderOrManager<'a> { package: PackageInterfaceHandle, path: &str, prev_package: Option<PackageInterfaceHandle>, - ) -> Result<Option<PhpMixed>> { + ) -> anyhow::Result<Option<PhpMixed>> { match self { Self::Interface(d) => d.borrow_mut().download3(package, path, prev_package).await, Self::Manager(d) => d.borrow().download(package, path, prev_package).await, @@ -31,7 +30,7 @@ impl<'a> DownloaderOrManager<'a> { package: PackageInterfaceHandle, path: &str, prev_package: Option<PackageInterfaceHandle>, - ) -> Result<Option<PhpMixed>> { + ) -> anyhow::Result<Option<PhpMixed>> { match self { Self::Interface(d) => { d.borrow_mut() @@ -50,7 +49,7 @@ impl<'a> DownloaderOrManager<'a> { &self, package: PackageInterfaceHandle, path: &str, - ) -> Result<Option<PhpMixed>> { + ) -> anyhow::Result<Option<PhpMixed>> { match self { Self::Interface(d) => d.borrow_mut().install2(package, path).await, Self::Manager(d) => d.borrow().install(package, path).await, @@ -62,7 +61,7 @@ impl<'a> DownloaderOrManager<'a> { package: PackageInterfaceHandle, prev_package: PackageInterfaceHandle, path: &str, - ) -> Result<Option<PhpMixed>> { + ) -> anyhow::Result<Option<PhpMixed>> { match self { Self::Interface(d) => d.borrow_mut().update(package, prev_package, path).await, Self::Manager(d) => d.borrow().update(package, prev_package, path).await, @@ -75,7 +74,7 @@ impl<'a> DownloaderOrManager<'a> { package: PackageInterfaceHandle, path: &str, prev_package: Option<PackageInterfaceHandle>, - ) -> Result<Option<PhpMixed>> { + ) -> anyhow::Result<Option<PhpMixed>> { match self { Self::Interface(d) => { d.borrow_mut() @@ -100,14 +99,14 @@ impl SyncHelper { path: String, package: PackageInterfaceHandle, prev_package: Option<PackageInterfaceHandle>, - ) -> Result<()> { + ) -> anyhow::Result<()> { let r#type = if prev_package.is_some() { "update" } else { "install" }; - let result: Result<()> = (|| -> Result<()> { + let result: anyhow::Result<()> = (|| -> anyhow::Result<()> { Self::r#await( r#loop, Some(Box::pin(async { @@ -176,8 +175,10 @@ impl SyncHelper { pub fn r#await( r#loop: &std::rc::Rc<std::cell::RefCell<Loop>>, - promise: Option<std::pin::Pin<Box<dyn std::future::Future<Output = Result<()>> + '_>>>, - ) -> Result<()> { + promise: Option< + std::pin::Pin<Box<dyn std::future::Future<Output = anyhow::Result<()>> + '_>>, + >, + ) -> anyhow::Result<()> { if let Some(promise) = promise { crate::util::sync_executor::block_on(r#loop.borrow_mut().wait(vec![promise], None))?; } diff --git a/crates/shirabe/src/util/tar.rs b/crates/shirabe/src/util/tar.rs index 95a6fde..55b6a96 100644 --- a/crates/shirabe/src/util/tar.rs +++ b/crates/shirabe/src/util/tar.rs @@ -1,13 +1,12 @@ //! ref: composer/src/Composer/Util/Tar.php -use anyhow::Result; use indexmap::IndexMap; use shirabe_php_shim::{PharData, RuntimeException}; pub struct Tar; impl Tar { - pub fn get_composer_json(path_to_archive: &str) -> Result<Option<String>> { + pub fn get_composer_json(path_to_archive: &str) -> anyhow::Result<Option<String>> { let phar = PharData::new(path_to_archive.to_string()); if !phar.valid() { @@ -17,7 +16,7 @@ impl Tar { Ok(Some(Self::extract_composer_json_from_folder(&phar)?)) } - fn extract_composer_json_from_folder(phar: &PharData) -> Result<String> { + fn extract_composer_json_from_folder(phar: &PharData) -> anyhow::Result<String> { if let Some(file) = phar.get("composer.json") { return Ok(file.get_content()); } diff --git a/crates/shirabe/src/util/zip.rs b/crates/shirabe/src/util/zip.rs index dbb2627..a671d63 100644 --- a/crates/shirabe/src/util/zip.rs +++ b/crates/shirabe/src/util/zip.rs @@ -1,6 +1,5 @@ //! ref: composer/src/Composer/Util/Zip.php -use anyhow::Result; use indexmap::IndexMap; use shirabe_php_shim::{ RuntimeException, ZipArchive, dirname, extension_loaded, implode, stream_get_contents, @@ -9,7 +8,7 @@ use shirabe_php_shim::{ pub struct Zip; impl Zip { - pub fn get_composer_json(path_to_zip: &str) -> Result<Option<String>> { + pub fn get_composer_json(path_to_zip: &str) -> anyhow::Result<Option<String>> { if !extension_loaded("zip") { return Err(RuntimeException { message: "The Zip Util requires PHP's zip extension".to_string(), @@ -43,7 +42,7 @@ impl Zip { Ok(content) } - fn locate_file(zip: &ZipArchive, filename: &str) -> Result<i64> { + fn locate_file(zip: &ZipArchive, filename: &str) -> anyhow::Result<i64> { // return root composer.json if it is there and is a file if let Some(index) = zip.locate_name(filename) && zip.get_from_index(index).is_some() |
