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/auth_helper.rs8
-rw-r--r--crates/shirabe/src/util/bitbucket.rs2
-rw-r--r--crates/shirabe/src/util/error_handler.rs2
-rw-r--r--crates/shirabe/src/util/filesystem.rs19
-rw-r--r--crates/shirabe/src/util/git.rs27
-rw-r--r--crates/shirabe/src/util/github.rs1
-rw-r--r--crates/shirabe/src/util/http/curl_downloader.rs11
-rw-r--r--crates/shirabe/src/util/http_downloader.rs2
-rw-r--r--crates/shirabe/src/util/package_sorter.rs1
-rw-r--r--crates/shirabe/src/util/perforce.rs4
-rw-r--r--crates/shirabe/src/util/process_executor.rs41
-rw-r--r--crates/shirabe/src/util/remote_filesystem.rs2
-rw-r--r--crates/shirabe/src/util/stream_context_factory.rs5
-rw-r--r--crates/shirabe/src/util/svn.rs12
14 files changed, 58 insertions, 79 deletions
diff --git a/crates/shirabe/src/util/auth_helper.rs b/crates/shirabe/src/util/auth_helper.rs
index f386b1e..584ce69 100644
--- a/crates/shirabe/src/util/auth_helper.rs
+++ b/crates/shirabe/src/util/auth_helper.rs
@@ -6,8 +6,8 @@ use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_php_shim::{
PHP_URL_HOST, PHP_URL_PATH, PHP_URL_SCHEME, PhpMixed, RuntimeException, base64_encode, explode,
- in_array, is_array, is_string, json_decode, parse_url, sprintf, str_replace, strpos,
- strtolower, substr, trim,
+ in_array, is_array, is_string, json_decode, parse_url, str_replace, strpos, strtolower, substr,
+ trim,
};
use crate::config::Config;
@@ -475,7 +475,7 @@ impl AuthHelper {
.and_then(|h| h.get("header"))
.and_then(|v| v.as_list())
{
- Some(list) => list.iter().cloned().collect(),
+ Some(list) => list.to_vec(),
None => vec![],
};
@@ -496,7 +496,9 @@ impl AuthHelper {
username,
)));
} else if password == "custom-headers" {
+ // TODO:
// Handle custom HTTP headers from auth.json
+ #[allow(unused_assignments)]
let mut custom_headers: PhpMixed = PhpMixed::Null;
// PHP: if (is_string($auth['username']))
// username field is always String in our IndexMap representation
diff --git a/crates/shirabe/src/util/bitbucket.rs b/crates/shirabe/src/util/bitbucket.rs
index 9c8d59b..8a1127a 100644
--- a/crates/shirabe/src/util/bitbucket.rs
+++ b/crates/shirabe/src/util/bitbucket.rs
@@ -451,7 +451,7 @@ impl Bitbucket {
return false;
}
- let access_token = match origin_config.get("access-token").map(|v| v.clone()) {
+ let access_token = match origin_config.get("access-token").cloned() {
Some(t) => t,
None => return false,
};
diff --git a/crates/shirabe/src/util/error_handler.rs b/crates/shirabe/src/util/error_handler.rs
index d883556..45ad28a 100644
--- a/crates/shirabe/src/util/error_handler.rs
+++ b/crates/shirabe/src/util/error_handler.rs
@@ -4,7 +4,7 @@ use crate::io::IOInterface;
use crate::io::IOInterfaceImmutable;
use shirabe_php_shim::{
E_ALL, E_DEPRECATED, E_USER_DEPRECATED, E_USER_WARNING, E_WARNING, ErrorException, PHP_EOL,
- PhpMixed, STDERR, debug_backtrace, error_reporting, filter_var_boolean, fwrite, ini_get,
+ STDERR, debug_backtrace, error_reporting, filter_var_boolean, fwrite, ini_get,
set_error_handler,
};
use std::cell::{Cell, RefCell};
diff --git a/crates/shirabe/src/util/filesystem.rs b/crates/shirabe/src/util/filesystem.rs
index ec1e65a..6dd2ab9 100644
--- a/crates/shirabe/src/util/filesystem.rs
+++ b/crates/shirabe/src/util/filesystem.rs
@@ -4,14 +4,13 @@ use shirabe_external_packages::composer::pcre::Preg;
use shirabe_external_packages::symfony::filesystem::exception::IOException;
use shirabe_external_packages::symfony::finder::Finder;
use shirabe_php_shim::{
- DIRECTORY_SEPARATOR, ErrorException, InvalidArgumentException, LogicException, PhpMixed,
- RuntimeException, UnexpectedValueException, array_pop, basename, chdir, clearstatcache,
- clearstatcache2, copy, count, dirname, error_get_last, explode, fclose, feof, file_exists,
- file_get_contents, file_put_contents, fileatime, filemtime, filesize, fopen, fread,
- function_exists, fwrite, implode, is_array, is_dir, is_file, is_link, is_readable, lstat,
- mkdir, react_promise_resolve, rename, rmdir, rtrim, sprintf, str_contains, str_repeat,
- str_replace, str_starts_with, strlen, strpos, strtolower, strtoupper, strtr, substr,
- substr_count, symlink, touch, unlink, usleep, var_export,
+ DIRECTORY_SEPARATOR, ErrorException, LogicException, PhpMixed, RuntimeException, array_pop,
+ basename, chdir, clearstatcache, clearstatcache2, copy, dirname, error_get_last, 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, rename, rmdir, rtrim, str_contains, str_repeat, str_replace,
+ str_starts_with, strlen, strpos, strtoupper, strtr, substr, substr_count, symlink, touch,
+ unlink, usleep, var_export,
};
use std::path::Path;
@@ -246,9 +245,9 @@ impl Filesystem {
for file in &ri {
if file.is_dir() {
- self.rmdir(&file.get_pathname())?;
+ self.rmdir(file.get_pathname())?;
} else {
- self.unlink(&file.get_pathname())?;
+ self.unlink(file.get_pathname())?;
}
}
diff --git a/crates/shirabe/src/util/git.rs b/crates/shirabe/src/util/git.rs
index 4ea15b7..f30f9f7 100644
--- a/crates/shirabe/src/util/git.rs
+++ b/crates/shirabe/src/util/git.rs
@@ -7,10 +7,9 @@ use std::sync::Mutex;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_php_shim::{
- InvalidArgumentException, PHP_EOL, PhpMixed, RuntimeException, array_map,
- array_merge_recursive, clearstatcache, count, explode, implode, in_array, is_array,
- is_callable, is_dir, preg_quote, rawurldecode, rawurlencode, str_contains, str_ends_with,
- str_replace, str_replace_array, strlen, strpos, substr, trim, version_compare,
+ InvalidArgumentException, PHP_EOL, PhpMixed, RuntimeException, array_map, clearstatcache,
+ explode, implode, in_array, is_callable, is_dir, preg_quote, rawurldecode, rawurlencode,
+ str_contains, str_ends_with, str_replace_array, strlen, strpos, substr, trim, version_compare,
};
use crate::config::Config;
@@ -175,10 +174,10 @@ impl Git {
let cwd_string = cwd.map(|s| s.to_string());
// PHP closure: $runCommands = function ($url) use (...) { ... };
- let mut run_commands_inline = |url_arg: &str,
- this_process: &mut ProcessExecutor,
- last_cmd: &mut PhpMixed,
- command_output: Option<&mut PhpMixed>|
+ let run_commands_inline = |url_arg: &str,
+ this_process: &mut ProcessExecutor,
+ last_cmd: &mut PhpMixed,
+ command_output: Option<&mut PhpMixed>|
-> i64 {
let collect_outputs = !command_output
.as_ref()
@@ -656,7 +655,7 @@ impl Git {
}
} else if let Some(m) = self.get_authentication_failure(url) {
// private non-github/gitlab/bitbucket repo that failed to authenticate
- let mut m1 = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default();
+ let m1 = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default();
let mut m2 = m.get(&CaptureKey::ByIndex(2)).cloned().unwrap_or_default();
let m3 = m.get(&CaptureKey::ByIndex(3)).cloned().unwrap_or_default();
let mut auth_parts: Option<String> = None;
@@ -746,7 +745,7 @@ impl Git {
username,
Some(password),
);
- let mut auth_helper = AuthHelper::new(self.io.clone(), self.config.clone());
+ let auth_helper = AuthHelper::new(self.io.clone(), self.config.clone());
let store_auth_enum = match &store_auth {
PhpMixed::String(s) if s == "prompt" => StoreAuth::Prompt,
PhpMixed::Bool(b) => StoreAuth::Bool(*b),
@@ -776,7 +775,6 @@ impl Git {
}
_ => last_command.as_string().unwrap_or("").to_string(),
};
- let mut error_msg = self.process.borrow().get_error_output().to_string();
if (credentials.len() as i64) > 0 {
last_command_str = self.mask_credentials(&last_command_str, &credentials);
error_msg = self.mask_credentials(&error_msg, &credentials);
@@ -923,9 +921,10 @@ impl Git {
pretty_version: Option<&str>,
) -> Result<bool> {
if self.check_ref_is_in_mirror(dir, r#ref)? {
- if Preg::is_match(r"{^[a-f0-9]{40}$}", r#ref) && pretty_version.is_some() {
- let branch =
- Preg::replace(r"{(?:^dev-|(?:\.x)?-dev$)}i", "", pretty_version.unwrap());
+ if Preg::is_match(r"{^[a-f0-9]{40}$}", r#ref)
+ && let Some(pretty_version) = pretty_version
+ {
+ let branch = Preg::replace(r"{(?:^dev-|(?:\.x)?-dev$)}i", "", pretty_version);
let mut branches: Option<String> = None;
let mut tags: Option<String> = None;
let mut output = String::new();
diff --git a/crates/shirabe/src/util/github.rs b/crates/shirabe/src/util/github.rs
index ab5efea..dae4954 100644
--- a/crates/shirabe/src/util/github.rs
+++ b/crates/shirabe/src/util/github.rs
@@ -6,7 +6,6 @@ use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_php_shim::{PhpMixed, date, stripos, strtolower};
use crate::config::Config;
-use crate::downloader::TransportException;
use crate::factory::Factory;
use crate::io::IOInterface;
use crate::io::IOInterfaceImmutable;
diff --git a/crates/shirabe/src/util/http/curl_downloader.rs b/crates/shirabe/src/util/http/curl_downloader.rs
index b49adf7..66ca326 100644
--- a/crates/shirabe/src/util/http/curl_downloader.rs
+++ b/crates/shirabe/src/util/http/curl_downloader.rs
@@ -406,12 +406,11 @@ impl CurlDownloader {
if curl_response.inner.get_status_code() >= 300
&& curl_response.inner.get_header("content-type").as_deref()
== Some("application/json")
+ && let Some(body) = curl_response.inner.get_body()
{
- if let Some(body) = curl_response.inner.get_body() {
- let decoded = shirabe_php_shim::json_decode(body, true)?;
- if let PhpMixed::Array(a) = decoded {
- HttpDownloader::output_warnings(self.io.clone(), &origin, &a)?;
- }
+ let decoded = shirabe_php_shim::json_decode(body, true)?;
+ if let PhpMixed::Array(a) = decoded {
+ HttpDownloader::output_warnings(self.io.clone(), &origin, &a)?;
}
}
@@ -527,7 +526,7 @@ impl CurlDownloader {
// Atomic rename of the `~` temp file to its final name (file mode).
if let Some(filename) = &filename {
- rename(&format!("{}~", filename), filename);
+ rename(format!("{}~", filename), filename);
}
self.resolve_job(id, curl_response.inner);
diff --git a/crates/shirabe/src/util/http_downloader.rs b/crates/shirabe/src/util/http_downloader.rs
index 9057899..a6b62d7 100644
--- a/crates/shirabe/src/util/http_downloader.rs
+++ b/crates/shirabe/src/util/http_downloader.rs
@@ -10,11 +10,9 @@ use shirabe_php_shim::{
extension_loaded, file_get_contents, function_exists, implode, is_numeric, rawurldecode,
stream_context_create, stripos, strpos, substr, ucfirst,
};
-use shirabe_semver::constraint::AnyConstraint;
use shirabe_semver::constraint::SimpleConstraint;
use crate::composer;
-use crate::composer::ComposerHandle;
use crate::config::Config;
use crate::downloader::TransportException;
use crate::io::IOInterface;
diff --git a/crates/shirabe/src/util/package_sorter.rs b/crates/shirabe/src/util/package_sorter.rs
index 8361dcc..6e0af01 100644
--- a/crates/shirabe/src/util/package_sorter.rs
+++ b/crates/shirabe/src/util/package_sorter.rs
@@ -4,7 +4,6 @@ use indexmap::IndexMap;
use shirabe_php_shim::{strnatcasecmp, version_compare};
use crate::package::Link;
-use crate::package::PackageInterface;
use crate::package::PackageInterfaceHandle;
pub struct PackageSorter;
diff --git a/crates/shirabe/src/util/perforce.rs b/crates/shirabe/src/util/perforce.rs
index 11d8cc5..4d4ddef 100644
--- a/crates/shirabe/src/util/perforce.rs
+++ b/crates/shirabe/src/util/perforce.rs
@@ -6,7 +6,7 @@ use shirabe_external_packages::composer::pcre::Preg;
use shirabe_external_packages::symfony::process::ExecutableFinder;
use shirabe_external_packages::symfony::process::Process;
use shirabe_php_shim::{
- Exception, PHP_EOL, PhpMixed, PhpResource, chdir, count, date, explode, fclose, feof, fgets,
+ Exception, PHP_EOL, PhpMixed, PhpResource, chdir, date, explode, fclose, feof, fgets,
file_get_contents, fopen, fwrite, gethostname, json_decode, str_replace_array, strcmp, strlen,
strpos, strrpos, substr, time, trim,
};
@@ -390,7 +390,7 @@ impl Perforce {
p4_create_client_command,
None,
None,
- file_get_contents(&self.get_p4_client_spec())
+ file_get_contents(self.get_p4_client_spec())
.map(PhpMixed::String)
.unwrap_or(PhpMixed::Null),
None,
diff --git a/crates/shirabe/src/util/process_executor.rs b/crates/shirabe/src/util/process_executor.rs
index fb486e3..98c3186 100644
--- a/crates/shirabe/src/util/process_executor.rs
+++ b/crates/shirabe/src/util/process_executor.rs
@@ -12,10 +12,9 @@ use shirabe_external_packages::symfony::process::Process;
use shirabe_external_packages::symfony::process::exception::ProcessSignaledException;
use shirabe_external_packages::symfony::process::exception::RuntimeException as SymfonyProcessRuntimeException;
use shirabe_php_shim::{
- LogicException, PHP_EOL, PhpMixed, RuntimeException, array_intersect, array_map,
- call_user_func, defined, escapeshellarg, explode, implode, in_array, is_array, is_dir,
- is_numeric, is_string, rtrim, sprintf, str_replace, strcspn, strlen, strpbrk, strtolower,
- strtr_array, substr_replace, trim, usleep,
+ LogicException, PHP_EOL, PhpMixed, array_intersect, array_map, call_user_func, escapeshellarg,
+ explode, implode, in_array, is_array, is_dir, is_numeric, is_string, rtrim, sprintf,
+ str_replace, strcspn, strlen, strpbrk, strtolower, strtr_array, substr_replace, trim, usleep,
};
use crate::io::IOInterface;
@@ -102,23 +101,13 @@ impl MockExpectation {
/// The `{return, stdout, stderr}` default-handler triple used for unmatched commands in non-strict
/// mode (`$defaultHandler` in PHP).
-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, Default)]
pub struct MockHandler {
pub r#return: i64,
pub stdout: String,
pub stderr: String,
}
-impl Default for MockHandler {
- fn default() -> Self {
- Self {
- r#return: 0,
- stdout: String::new(),
- stderr: String::new(),
- }
- }
-}
-
struct Job {
id: i64,
status: i64,
@@ -232,7 +221,7 @@ impl ProcessExecutor {
cwd: Option<&str>,
env: Option<IndexMap<String, String>>,
tty: bool,
- mut output: O,
+ output: O,
) -> Result<Option<i64>>
where
O: IntoExecOutput<'o>,
@@ -323,7 +312,7 @@ impl ProcessExecutor {
Err(mut output) => {
let capture_output = self.capture_output;
let mut io = self.io.clone();
- let mut callback = move |r#type: &str, buffer: &str| {
+ let callback = move |r#type: &str, buffer: &str| {
Self::output_handler(capture_output, &mut io, r#type, buffer);
false
};
@@ -381,19 +370,21 @@ impl ProcessExecutor {
let mut env: Option<IndexMap<String, String>> = None;
let requires_git_dir_env = self.requires_git_dir_env(&command);
- if cwd.is_some() && requires_git_dir_env {
- let is_bare_repository = !is_dir(&format!("{}/.git", rtrim(cwd.unwrap(), Some("/"))));
+ if let Some(cwd) = cwd
+ && requires_git_dir_env
+ {
+ let is_bare_repository = !is_dir(format!("{}/.git", rtrim(cwd, Some("/"))));
if is_bare_repository {
let mut config_value = PhpMixed::String(String::new());
let mut git_env: IndexMap<String, String> = IndexMap::new();
- git_env.insert("GIT_DIR".to_string(), cwd.unwrap().to_string());
+ git_env.insert("GIT_DIR".to_string(), cwd.to_string());
self.run_process(
PhpMixed::List(vec![
PhpMixed::String("git".to_string()),
PhpMixed::String("config".to_string()),
PhpMixed::String("safe.bareRepository".to_string()),
]),
- cwd,
+ Some(cwd),
Some(git_env.clone()),
tty,
&mut config_value,
@@ -419,7 +410,7 @@ impl ProcessExecutor {
&mut self,
command: PhpMixed,
cwd: Option<&str>,
- mut output: O,
+ output: O,
) -> Result<i64>
where
O: IntoExecOutput<'o>,
@@ -688,7 +679,7 @@ impl ProcessExecutor {
self.output_command_run(&command, cwd.as_deref(), true);
- let process_result: Result<Process> = (if is_string(&command) {
+ let process_result: Result<Process> = if is_string(&command) {
Process::from_shell_commandline(
command.as_string().unwrap_or(""),
cwd.as_deref(),
@@ -712,7 +703,7 @@ impl ProcessExecutor {
code: 0,
}
.into())
- });
+ };
let process = match process_result {
Ok(p) => p,
Err(e) => {
@@ -908,7 +899,7 @@ impl ProcessExecutor {
} else if let PhpMixed::List(list) = command {
let parts: Vec<String> = array_map(
|v| Self::escape(v.as_string().unwrap_or("")),
- &list.iter().cloned().collect::<Vec<_>>(),
+ &list.to_vec(),
);
implode(" ", &parts)
} else {
diff --git a/crates/shirabe/src/util/remote_filesystem.rs b/crates/shirabe/src/util/remote_filesystem.rs
index 5bd9036..ca818fc 100644
--- a/crates/shirabe/src/util/remote_filesystem.rs
+++ b/crates/shirabe/src/util/remote_filesystem.rs
@@ -8,7 +8,7 @@ use shirabe_php_shim::{
STREAM_NOTIFY_FAILURE, STREAM_NOTIFY_FILE_SIZE_IS, STREAM_NOTIFY_PROGRESS,
array_replace_recursive, base64_encode, explode, extension_loaded, file_put_contents,
filter_var_boolean, gethostbyname, http_clear_last_response_headers,
- http_get_last_response_headers, ini_get, json_decode, parse_url, preg_quote, sprintf, strpos,
+ http_get_last_response_headers, ini_get, json_decode, parse_url, preg_quote, strpos,
strtolower, strtr, substr, trim, zlib_decode,
};
diff --git a/crates/shirabe/src/util/stream_context_factory.rs b/crates/shirabe/src/util/stream_context_factory.rs
index db48122..1747cd6 100644
--- a/crates/shirabe/src/util/stream_context_factory.rs
+++ b/crates/shirabe/src/util/stream_context_factory.rs
@@ -4,12 +4,11 @@ use indexmap::IndexMap;
use shirabe_external_packages::composer::ca_bundle::CaBundle;
use shirabe_php_shim::{
HHVM_VERSION, PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION, PhpMixed,
- RuntimeException, array_replace_recursive, curl_version, extension_loaded, function_exists,
- php_uname, stream_context_create, stripos, uasort,
+ array_replace_recursive, curl_version, extension_loaded, function_exists, php_uname,
+ stream_context_create, stripos, uasort,
};
use crate::composer;
-use crate::composer::ComposerHandle;
use crate::downloader::TransportException;
use crate::repository::PlatformRepository;
use crate::util::Filesystem;
diff --git a/crates/shirabe/src/util/svn.rs b/crates/shirabe/src/util/svn.rs
index 5375447..096d8c3 100644
--- a/crates/shirabe/src/util/svn.rs
+++ b/crates/shirabe/src/util/svn.rs
@@ -381,7 +381,7 @@ impl Svn {
let auth_for_host = auth_config
.as_array()
.and_then(|m| m.get(host_str))
- .map(|v| v.clone());
+ .cloned();
if let Some(entry) = auth_for_host
&& let Some(entry_arr) = entry.as_array()
{
@@ -416,19 +416,13 @@ impl Svn {
return false;
}
};
- let user_val = uri_arr
- .get("user")
- .map(|v| v.clone())
- .unwrap_or(PhpMixed::Null);
+ let user_val = uri_arr.get("user").cloned().unwrap_or(PhpMixed::Null);
if empty(&user_val) {
self.has_auth = Some(false);
return false;
}
- let pass_val = uri_arr
- .get("pass")
- .map(|v| v.clone())
- .unwrap_or(PhpMixed::Null);
+ let pass_val = uri_arr.get("pass").cloned().unwrap_or(PhpMixed::Null);
self.credentials = Some(SvnCredentials {
username: user_val.as_string().unwrap_or("").to_string(),
password: if !empty(&pass_val) {