aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/downloader
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-27 03:52:05 +0900
committernsfisis <nsfisis@gmail.com>2026-06-27 04:21:34 +0900
commit2b51554ff59d1e5cbf8dd2db65d278b0202a9102 (patch)
treef4d9b0abf4df9b5e363e3bd65511d70e3d5ada00 /crates/shirabe/src/downloader
parentcc07b5abb83a40d678401c335bdc49bb81b72c5f (diff)
downloadphp-shirabe-2b51554ff59d1e5cbf8dd2db65d278b0202a9102.tar.gz
php-shirabe-2b51554ff59d1e5cbf8dd2db65d278b0202a9102.tar.zst
php-shirabe-2b51554ff59d1e5cbf8dd2db65d278b0202a9102.zip
refactor: fix compiler warnings and clippy warnings
Diffstat (limited to 'crates/shirabe/src/downloader')
-rw-r--r--crates/shirabe/src/downloader/archive_downloader.rs8
-rw-r--r--crates/shirabe/src/downloader/download_manager.rs6
-rw-r--r--crates/shirabe/src/downloader/file_downloader.rs28
-rw-r--r--crates/shirabe/src/downloader/git_downloader.rs5
-rw-r--r--crates/shirabe/src/downloader/path_downloader.rs2
-rw-r--r--crates/shirabe/src/downloader/perforce_downloader.rs6
-rw-r--r--crates/shirabe/src/downloader/svn_downloader.rs2
-rw-r--r--crates/shirabe/src/downloader/vcs_downloader.rs5
-rw-r--r--crates/shirabe/src/downloader/zip_downloader.rs99
9 files changed, 74 insertions, 87 deletions
diff --git a/crates/shirabe/src/downloader/archive_downloader.rs b/crates/shirabe/src/downloader/archive_downloader.rs
index e8ce9b3..b1bdee7 100644
--- a/crates/shirabe/src/downloader/archive_downloader.rs
+++ b/crates/shirabe/src/downloader/archive_downloader.rs
@@ -12,7 +12,6 @@ use std::path::{Path, PathBuf};
use crate::dependency_resolver::operation::InstallOperation;
use crate::downloader::DownloaderInterface;
use crate::downloader::FileDownloader;
-use crate::io::IOInterface;
use crate::io::IOInterfaceImmutable;
use crate::package::PackageInterfaceHandle;
use crate::util::Filesystem;
@@ -165,11 +164,8 @@ pub trait ArchiveDownloader {
}
let content_dir = get_folder_content(&temporary_dir);
- let single_dir_at_top_level = content_dir.len() == 1
- && content_dir
- .first()
- .map(|file| is_dir(file))
- .unwrap_or(false);
+ let single_dir_at_top_level =
+ content_dir.len() == 1 && content_dir.first().map(is_dir).unwrap_or(false);
if rename_as_one {
// if the target $path is clear, we can rename the whole package in one go instead of looping over the contents
diff --git a/crates/shirabe/src/downloader/download_manager.rs b/crates/shirabe/src/downloader/download_manager.rs
index 15275a9..183813d 100644
--- a/crates/shirabe/src/downloader/download_manager.rs
+++ b/crates/shirabe/src/downloader/download_manager.rs
@@ -6,8 +6,8 @@ use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_php_shim::{
InvalidArgumentException, LogicException, PhpMixed, RuntimeException, array_keys,
- array_reverse, array_shift, dirname, get_class, implode, in_array, preg_quote, rtrim, sprintf,
- str_replace, strtolower, usort,
+ array_reverse, array_shift, dirname, implode, in_array, preg_quote, rtrim, str_replace,
+ strtolower, usort,
};
use crate::downloader::DownloaderInterface;
@@ -162,7 +162,7 @@ impl DownloadManager {
shirabe_php_shim::get_class_obj(&*downloader.borrow()),
downloader_installation_source,
installation_source.clone().unwrap_or_default(),
- package.to_string(),
+ package,
),
code: 0,
}
diff --git a/crates/shirabe/src/downloader/file_downloader.rs b/crates/shirabe/src/downloader/file_downloader.rs
index 6b2162a..b03db38 100644
--- a/crates/shirabe/src/downloader/file_downloader.rs
+++ b/crates/shirabe/src/downloader/file_downloader.rs
@@ -26,13 +26,9 @@ use crate::event_dispatcher::EventDispatcher;
use crate::exception::IrrecoverableDownloadException;
use crate::io::IOInterface;
use crate::io::IOInterfaceImmutable;
-use crate::io::IOInterfaceMutable;
use crate::io::NullIO;
use crate::package::PackageInterfaceHandle;
use crate::package::comparer::Comparer;
-use crate::plugin::PluginEvents;
-use crate::plugin::PostFileDownloadEvent;
-use crate::plugin::PreFileDownloadEvent;
use crate::util::Filesystem;
use crate::util::HttpDownloader;
use crate::util::Platform;
@@ -111,7 +107,7 @@ impl FileDownloader {
))))
});
- let mut this = Self {
+ let this = Self {
io,
config,
http_downloader,
@@ -123,10 +119,12 @@ impl FileDownloader {
additional_cleanup_paths: IndexMap::new(),
};
- if this.cache.is_some() && this.cache.as_ref().unwrap().borrow().gc_is_necessary() {
+ if let Some(cache) = &this.cache
+ && cache.borrow().gc_is_necessary()
+ {
// PHP: writeError('Running cache garbage collection', true, io_interface::VERY_VERBOSE)
this.io.write_error("Running cache garbage collection");
- this.cache.as_ref().unwrap().borrow_mut().gc(
+ cache.borrow_mut().gc(
this.config
.borrow_mut()
.get("cache-files-ttl")
@@ -537,8 +535,8 @@ impl DownloaderInterface for FileDownloader {
}
self.filesystem.borrow_mut().ensure_directory_exists(path)?;
self.filesystem.borrow_mut().rename(
- &self.get_file_name(package.clone(), path),
- &format!(
+ self.get_file_name(package.clone(), path),
+ format!(
"{}/{}",
path,
self.get_dist_path(package.clone(), PATHINFO_BASENAME)
@@ -626,10 +624,10 @@ impl ChangeReportInterface for FileDownloader {
// httpDownloader->wait() / process->wait(); the single-threaded sync bridge block_on's the
// download/install futures, so a rejection surfaces directly as the Err captured below.
let result: Result<String> = (|| -> Result<String> {
- if is_dir(&format!("{}_compare", target_dir)) {
+ if is_dir(format!("{}_compare", target_dir)) {
self.filesystem
.borrow_mut()
- .remove_directory(&format!("{}_compare", target_dir))?;
+ .remove_directory(format!("{}_compare", target_dir))?;
}
tokio::runtime::Runtime::new()
@@ -655,7 +653,7 @@ impl ChangeReportInterface for FileDownloader {
let output = comparer.get_changed_as_string(true, false);
self.filesystem
.borrow_mut()
- .remove_directory(&format!("{}_compare", target_dir))?;
+ .remove_directory(format!("{}_compare", target_dir))?;
Ok(output)
})();
@@ -710,9 +708,11 @@ impl FileDownloader {
pub(crate) fn clear_last_cache_write(&self, package: PackageInterfaceHandle) {
let mut last_cache_writes = self.last_cache_writes.lock().unwrap();
- if self.cache.is_some() && last_cache_writes.contains_key(&package.get_name()) {
+ if let Some(cache) = &self.cache
+ && last_cache_writes.contains_key(&package.get_name())
+ {
let key = last_cache_writes.get(&package.get_name()).unwrap().clone();
- self.cache.as_ref().unwrap().borrow_mut().remove(&key);
+ cache.borrow_mut().remove(&key);
last_cache_writes.shift_remove(&package.get_name());
}
}
diff --git a/crates/shirabe/src/downloader/git_downloader.rs b/crates/shirabe/src/downloader/git_downloader.rs
index a3666d0..fd044f8 100644
--- a/crates/shirabe/src/downloader/git_downloader.rs
+++ b/crates/shirabe/src/downloader/git_downloader.rs
@@ -6,7 +6,7 @@ use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_php_shim::{
PhpMixed, RuntimeException, array_map, basename, dirname, implode, in_array, is_dir,
- preg_quote, realpath, rtrim, sprintf, strlen, strpos, substr, trim, version_compare,
+ preg_quote, realpath, rtrim, strlen, strpos, substr, trim, version_compare,
};
use crate::cache::Cache;
@@ -18,7 +18,6 @@ use crate::downloader::VcsDownloader;
use crate::downloader::VcsDownloaderBase;
use crate::io::IOInterface;
use crate::io::IOInterfaceImmutable;
-use crate::package::PackageInterface;
use crate::package::PackageInterfaceHandle;
use crate::util::Filesystem;
use crate::util::Git as GitUtil;
@@ -1395,7 +1394,7 @@ impl VcsDownloader for GitDownloader {
fn has_metadata_repository(&self, path: &str) -> bool {
let path = self.normalize_path(path);
- is_dir(&format!("{}/.git", path))
+ is_dir(format!("{}/.git", path))
}
}
diff --git a/crates/shirabe/src/downloader/path_downloader.rs b/crates/shirabe/src/downloader/path_downloader.rs
index 35c3709..694f758 100644
--- a/crates/shirabe/src/downloader/path_downloader.rs
+++ b/crates/shirabe/src/downloader/path_downloader.rs
@@ -4,7 +4,6 @@ use crate::io::io_interface;
use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::symfony::filesystem::Filesystem as SymfonyFilesystem;
-use shirabe_external_packages::symfony::filesystem::exception::IOException;
use shirabe_php_shim::{
DIRECTORY_SEPARATOR, PHP_WINDOWS_VERSION_MAJOR, PHP_WINDOWS_VERSION_MINOR, PhpMixed,
RuntimeException, file_exists, function_exists, is_dir, realpath,
@@ -14,7 +13,6 @@ use crate::cache::Cache;
use crate::config::Config;
use crate::dependency_resolver::operation::InstallOperation;
use crate::dependency_resolver::operation::UninstallOperation;
-use crate::downloader::ChangeReportInterface;
use crate::downloader::DownloaderInterface;
use crate::downloader::FileDownloader;
use crate::downloader::VcsCapableDownloaderInterface;
diff --git a/crates/shirabe/src/downloader/perforce_downloader.rs b/crates/shirabe/src/downloader/perforce_downloader.rs
index 687b7ef..f93cfa8 100644
--- a/crates/shirabe/src/downloader/perforce_downloader.rs
+++ b/crates/shirabe/src/downloader/perforce_downloader.rs
@@ -8,7 +8,6 @@ use crate::downloader::VcsDownloader;
use crate::downloader::VcsDownloaderBase;
use crate::io::IOInterface;
use crate::io::IOInterfaceImmutable;
-use crate::package::PackageInterface;
use crate::package::PackageInterfaceHandle;
use crate::repository::VcsRepository;
use crate::util::Filesystem;
@@ -17,7 +16,6 @@ use crate::util::ProcessExecutor;
use anyhow::Result;
use indexmap::IndexMap;
use shirabe_php_shim::PhpMixed;
-use std::any::Any;
#[derive(Debug)]
pub struct PerforceDownloader {
@@ -48,8 +46,8 @@ impl PerforceDownloader {
}
pub fn init_perforce(&mut self, package: PackageInterfaceHandle, path: String, url: String) {
- if self.perforce.is_some() {
- self.perforce.as_mut().unwrap().initialize_path(&path);
+ if let Some(perforce) = self.perforce.as_mut() {
+ perforce.initialize_path(&path);
return;
}
diff --git a/crates/shirabe/src/downloader/svn_downloader.rs b/crates/shirabe/src/downloader/svn_downloader.rs
index 1a7d81d..8c13a05 100644
--- a/crates/shirabe/src/downloader/svn_downloader.rs
+++ b/crates/shirabe/src/downloader/svn_downloader.rs
@@ -447,7 +447,7 @@ impl VcsDownloader for SvnDownloader {
}
fn has_metadata_repository(&self, path: &str) -> bool {
- is_dir(&format!("{}/.svn", path))
+ is_dir(format!("{}/.svn", path))
}
}
diff --git a/crates/shirabe/src/downloader/vcs_downloader.rs b/crates/shirabe/src/downloader/vcs_downloader.rs
index 78b3ae7..8084c37 100644
--- a/crates/shirabe/src/downloader/vcs_downloader.rs
+++ b/crates/shirabe/src/downloader/vcs_downloader.rs
@@ -4,9 +4,8 @@ use crate::io::io_interface;
use anyhow::Result;
use indexmap::IndexMap;
use shirabe_php_shim::{
- InvalidArgumentException, PhpMixed, RuntimeException, array_map, array_shift, count, explode,
- get_class, get_class_err, implode, rawurldecode, realpath, str_replace, strlen, strpos, substr,
- trim,
+ InvalidArgumentException, PhpMixed, RuntimeException, array_map, array_shift, explode,
+ get_class_err, implode, rawurldecode, realpath, str_replace, strlen, strpos, substr, trim,
};
use crate::config::Config;
diff --git a/crates/shirabe/src/downloader/zip_downloader.rs b/crates/shirabe/src/downloader/zip_downloader.rs
index 80ce6f9..6f3c6e5 100644
--- a/crates/shirabe/src/downloader/zip_downloader.rs
+++ b/crates/shirabe/src/downloader/zip_downloader.rs
@@ -2,9 +2,7 @@
use crate::downloader::ArchiveDownloader;
use crate::downloader::ChangeReportInterface;
-use crate::downloader::DownloaderInterface;
use crate::downloader::FileDownloader;
-use crate::io::IOInterface;
use crate::io::IOInterfaceImmutable;
use crate::package::PackageInterfaceHandle;
use crate::util::IniHelper;
@@ -13,7 +11,6 @@ use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_external_packages::symfony::process::ExecutableFinder;
-use shirabe_external_packages::symfony::process::Process;
use shirabe_php_shim::{
DIRECTORY_SEPARATOR, ErrorException, PhpMixed, RuntimeException, UnexpectedValueException,
ZipArchive, bin2hex, class_exists, file_exists, file_get_contents, filesize, function_exists,
@@ -290,69 +287,69 @@ impl ZipDownloader {
zip_archive.open(file, 0)
};
- if retval.is_ok() {
- let archive_size = filesize(file);
- let total_files = zip_archive.count();
- if total_files > 0 {
- let mut total_size: i64 = 0;
- let mut inspect_all = false;
- let mut files_to_inspect = total_files.min(5);
- let mut i: i64 = 0;
- while i < files_to_inspect {
- let stat_index = if inspect_all {
- i
- } else {
- random_int(0..total_files)
- };
- if let Some(stat) = zip_archive.stat_index(stat_index) {
- let size = stat.get("size").and_then(|v| v.as_int()).unwrap_or(0);
- let comp_size =
- stat.get("comp_size").and_then(|v| v.as_int()).unwrap_or(0);
- total_size += size;
- if !inspect_all && size > comp_size * 200 {
- total_size = 0;
- inspect_all = true;
- i = -1;
- files_to_inspect = total_files;
+ match retval {
+ Ok(_) => {
+ let archive_size = filesize(file);
+ let total_files = zip_archive.count();
+ if total_files > 0 {
+ let mut total_size: i64 = 0;
+ let mut inspect_all = false;
+ let mut files_to_inspect = total_files.min(5);
+ let mut i: i64 = 0;
+ while i < files_to_inspect {
+ let stat_index = if inspect_all {
+ i
+ } else {
+ random_int(0..total_files)
+ };
+ if let Some(stat) = zip_archive.stat_index(stat_index) {
+ let size = stat.get("size").and_then(|v| v.as_int()).unwrap_or(0);
+ let comp_size =
+ stat.get("comp_size").and_then(|v| v.as_int()).unwrap_or(0);
+ total_size += size;
+ if !inspect_all && size > comp_size * 200 {
+ total_size = 0;
+ inspect_all = true;
+ i = -1;
+ files_to_inspect = total_files;
+ }
}
+ i += 1;
}
- i += 1;
- }
- if let Some(archive_sz) = archive_size
- && total_size > archive_sz * 100
- && total_size > 50 * 1024 * 1024
- {
- return Err(RuntimeException {
+ if let Some(archive_sz) = archive_size
+ && total_size > archive_sz * 100
+ && total_size > 50 * 1024 * 1024
+ {
+ return Err(RuntimeException {
message: format!(
"Invalid zip file for \"{}\" with compression ratio >99% (possible zip bomb)",
package.get_name(),
),
code: 0,
}.into());
+ }
}
- }
- let extract_result = zip_archive.extract_to(path)?;
+ let extract_result = zip_archive.extract_to(path)?;
- if extract_result {
- zip_archive.close();
- return Ok(None);
- }
+ if extract_result {
+ zip_archive.close();
+ return Ok(None);
+ }
- Err(RuntimeException {
- message: format!(
- "There was an error extracting the ZIP file for \"{}\", it is either corrupted or using an invalid format.",
- package.get_name(),
- ),
- code: 0,
- }.into())
- } else {
- let code = retval.unwrap_err();
- Err(UnexpectedValueException {
+ Err(RuntimeException {
+ message: format!(
+ "There was an error extracting the ZIP file for \"{}\", it is either corrupted or using an invalid format.",
+ package.get_name(),
+ ),
+ code: 0,
+ }.into())
+ }
+ Err(code) => Err(UnexpectedValueException {
message: self.get_error_message(code, file).trim_end().to_string(),
code,
}
- .into())
+ .into()),
}
})();