diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-20 01:16:50 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-20 02:22:41 +0900 |
| commit | efec43b3b8827820cf35fe1b73d8e33f5fe84eb4 (patch) | |
| tree | a62bbba72324de48be5f8e689559f8d9e288fc61 /crates/shirabe/src/downloader | |
| parent | cac18ef73a39b4ac41fa4d6ccb753804d4c42cb7 (diff) | |
| download | php-shirabe-efec43b3b8827820cf35fe1b73d8e33f5fe84eb4.tar.gz php-shirabe-efec43b3b8827820cf35fe1b73d8e33f5fe84eb4.tar.zst php-shirabe-efec43b3b8827820cf35fe1b73d8e33f5fe84eb4.zip | |
refactor: auto-fix clippy warnings
Diffstat (limited to 'crates/shirabe/src/downloader')
| -rw-r--r-- | crates/shirabe/src/downloader/file_downloader.rs | 65 | ||||
| -rw-r--r-- | crates/shirabe/src/downloader/fossil_downloader.rs | 6 | ||||
| -rw-r--r-- | crates/shirabe/src/downloader/git_downloader.rs | 60 | ||||
| -rw-r--r-- | crates/shirabe/src/downloader/hg_downloader.rs | 4 | ||||
| -rw-r--r-- | crates/shirabe/src/downloader/path_downloader.rs | 2 | ||||
| -rw-r--r-- | crates/shirabe/src/downloader/perforce_downloader.rs | 9 | ||||
| -rw-r--r-- | crates/shirabe/src/downloader/svn_downloader.rs | 19 | ||||
| -rw-r--r-- | crates/shirabe/src/downloader/vcs_downloader.rs | 22 | ||||
| -rw-r--r-- | crates/shirabe/src/downloader/xz_downloader.rs | 2 | ||||
| -rw-r--r-- | crates/shirabe/src/downloader/zip_downloader.rs | 53 |
10 files changed, 119 insertions, 123 deletions
diff --git a/crates/shirabe/src/downloader/file_downloader.rs b/crates/shirabe/src/downloader/file_downloader.rs index e5112cc..3c4f7e2 100644 --- a/crates/shirabe/src/downloader/file_downloader.rs +++ b/crates/shirabe/src/downloader/file_downloader.rs @@ -201,7 +201,7 @@ impl DownloaderInterface for FileDownloader { cache_key, }); } - debug_assert!(urls.len() > 0); + debug_assert!(!urls.is_empty()); let file_name = self.get_file_name(package.clone(), path); self.filesystem.borrow_mut().ensure_directory_exists(path)?; @@ -253,13 +253,13 @@ impl DownloaderInterface for FileDownloader { // mark the file as having been written in cache even though it is only read from cache, so that if // the cache is corrupt the archive will be deleted and the next attempt will re-download it // see https://github.com/composer/composer/issues/10028 - if let Some(cache) = self.cache.as_ref() { - if !cache.borrow().is_read_only() { - self.last_cache_writes - .lock() - .unwrap() - .insert(package.get_name().to_string(), cache_key.clone()); - } + if let Some(cache) = self.cache.as_ref() + && !cache.borrow().is_read_only() + { + self.last_cache_writes + .lock() + .unwrap() + .insert(package.get_name().to_string(), cache_key.clone()); } } else { if output { @@ -304,14 +304,14 @@ impl DownloaderInterface for FileDownloader { ); } - if let Some(cache) = self.cache.as_ref() { - if !cache.borrow().is_read_only() { - self.last_cache_writes - .lock() - .unwrap() - .insert(package.get_name().to_string(), cache_key.clone()); - cache.borrow_mut().copy_from(&cache_key, &file_name); - } + if let Some(cache) = self.cache.as_ref() + && !cache.borrow().is_read_only() + { + self.last_cache_writes + .lock() + .unwrap() + .insert(package.get_name().to_string(), cache_key.clone()); + cache.borrow_mut().copy_from(&cache_key, &file_name); } response.collect(); @@ -366,7 +366,7 @@ impl DownloaderInterface for FileDownloader { if !urls.is_empty() { urls.remove(0); } - if urls.len() > 0 { + if !urls.is_empty() { let code = e .downcast_ref::<TransportException>() .map_or(0, |te| te.get_code()); @@ -414,19 +414,18 @@ impl DownloaderInterface for FileDownloader { .into()); } - if let Some(checksum) = checksum.as_deref() { - if !checksum.is_empty() - && hash_file("sha1", &file_name).as_deref() != Some(checksum) - { - return Err(UnexpectedValueException { - message: format!( - "The checksum verification of the file failed (downloaded from {})", - url.base - ), - code: 0, - } - .into()); + if let Some(checksum) = checksum.as_deref() + && !checksum.is_empty() + && hash_file("sha1", &file_name).as_deref() != Some(checksum) + { + return Err(UnexpectedValueException { + message: format!( + "The checksum verification of the file failed (downloaded from {})", + url.base + ), + code: 0, } + .into()); } // TODO(plugin): dispatch PostFileDownloadEvent. @@ -526,7 +525,7 @@ impl DownloaderInterface for FileDownloader { // clean up the target directory, unless it contains the vendor dir, as the vendor dir contains // the file to be installed. This is the case when installing with create-project in the current directory // but in that case we ensure the directory is empty already in ProjectInstaller so no need to empty it here. - if false == { + if !{ let normalized_vendor = self.filesystem.borrow_mut().normalize_path(&vendor_dir); let normalized_path = self .filesystem @@ -620,7 +619,7 @@ impl ChangeReportInterface for FileDownloader { ); self.io .borrow_mut() - .load_configuration(&mut *self.config.borrow_mut())?; + .load_configuration(&mut self.config.borrow_mut())?; let target_dir = Filesystem::trim_trailing_slash(path); // PHP attaches an onRejected handler to capture the error and drives the promise via @@ -721,7 +720,7 @@ impl FileDownloader { pub(crate) fn add_cleanup_path(&mut self, package: PackageInterfaceHandle, path: &str) { self.additional_cleanup_paths .entry(package.get_name()) - .or_insert_with(Vec::new) + .or_default() .push(path.to_string()); } @@ -786,7 +785,7 @@ impl FileDownloader { let mut url = url.to_string(); if package.get_dist_reference().is_some() { url = UrlUtil::update_dist_reference( - &*self.config.borrow(), + &self.config.borrow(), url, &package.get_dist_reference().unwrap(), ); diff --git a/crates/shirabe/src/downloader/fossil_downloader.rs b/crates/shirabe/src/downloader/fossil_downloader.rs index 2c4e7de..ab98168 100644 --- a/crates/shirabe/src/downloader/fossil_downloader.rs +++ b/crates/shirabe/src/downloader/fossil_downloader.rs @@ -276,7 +276,11 @@ impl ChangeReportInterface for FossilDownloader { let output = output.trim().to_string(); - Ok(if output.len() > 0 { Some(output) } else { None }) + Ok(if !output.is_empty() { + Some(output) + } else { + None + }) } } diff --git a/crates/shirabe/src/downloader/git_downloader.rs b/crates/shirabe/src/downloader/git_downloader.rs index c38e491..0a6e242 100644 --- a/crates/shirabe/src/downloader/git_downloader.rs +++ b/crates/shirabe/src/downloader/git_downloader.rs @@ -208,7 +208,7 @@ impl GitDownloader { if unpushed_changes.is_some() && i == 0 { let mut output = String::new(); self.inner.process.borrow_mut().execute_args( - &vec!["git".to_string(), "fetch".to_string(), "--all".to_string()], + &["git".to_string(), "fetch".to_string(), "--all".to_string()], &mut output, Some(path.clone()), ); @@ -278,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. @@ -287,7 +287,7 @@ impl GitDownloader { { let mut output = String::new(); if self.inner.process.borrow_mut().execute_args( - &vec!["git".to_string(), "branch".to_string(), "-r".to_string()], + &["git".to_string(), "branch".to_string(), "-r".to_string()], &mut output, Some(path.to_string()), ) == 0 @@ -483,7 +483,7 @@ impl GitDownloader { pub(crate) fn update_origin_url(&mut self, path: &str, url: &str) { let mut output = String::new(); self.inner.process.borrow_mut().execute_args( - &vec![ + &[ "git".to_string(), "remote".to_string(), "set-url".to_string(), @@ -503,7 +503,7 @@ impl GitDownloader { if Preg::is_match3( &format!( "{{^(?:https?|git)://{}/([^/]+)/([^/]+?)(?:\\.git)?$}}", - GitUtil::get_github_domains_regex(&*self.inner.config.borrow()) + GitUtil::get_github_domains_regex(&self.inner.config.borrow()) ), url, Some(&mut match_), @@ -549,7 +549,7 @@ impl GitDownloader { let path = self.normalize_path(path); let mut output = String::new(); if self.inner.process.borrow_mut().execute_args( - &vec!["git".to_string(), "clean".to_string(), "-df".to_string()], + &["git".to_string(), "clean".to_string(), "-df".to_string()], &mut output, Some(path.clone()), ) != 0 @@ -562,7 +562,7 @@ impl GitDownloader { } let mut output = String::new(); if self.inner.process.borrow_mut().execute_args( - &vec!["git".to_string(), "reset".to_string(), "--hard".to_string()], + &["git".to_string(), "reset".to_string(), "--hard".to_string()], &mut output, Some(path.clone()), ) != 0 @@ -585,7 +585,7 @@ impl GitDownloader { let path = self.normalize_path(path); let mut output = String::new(); if self.inner.process.borrow_mut().execute_args( - &vec![ + &[ "git".to_string(), "stash".to_string(), "--include-untracked".to_string(), @@ -611,7 +611,7 @@ impl GitDownloader { let path = self.normalize_path(path); let mut output = String::new(); if self.inner.process.borrow_mut().execute_args( - &vec!["git".to_string(), "diff".to_string(), "HEAD".to_string()], + &["git".to_string(), "diff".to_string(), "HEAD".to_string()], &mut output, Some(path.clone()), ) != 0 @@ -829,7 +829,7 @@ impl VcsDownloader for GitDownloader { { self.cached_packages .entry(package.get_id()) - .or_insert_with(IndexMap::new) + .or_default() .insert(r#ref.as_deref().unwrap_or("").to_string(), true); } } else if git_version.is_none() { @@ -880,12 +880,11 @@ impl VcsDownloader for GitDownloader { cache_path.clone(), ]; let transport_options = package.get_transport_options(); - if let Some(git_opts) = transport_options.get("git").and_then(|v| v.as_array()) { - if let Some(single) = git_opts.get("single_use_clone").and_then(|v| v.as_bool()) { - if single { - clone_flags = vec![]; - } - } + if let Some(git_opts) = transport_options.get("git").and_then(|v| v.as_array()) + && let Some(single) = git_opts.get("single_use_clone").and_then(|v| v.as_bool()) + && single + { + clone_flags = vec![]; } commands = vec![ @@ -1057,7 +1056,7 @@ impl VcsDownloader for GitDownloader { let mut output = String::new(); if self.inner.process.borrow_mut().execute_args( - &vec![ + &[ "git".to_string(), "rev-parse".to_string(), "--quiet".to_string(), @@ -1118,7 +1117,7 @@ impl VcsDownloader for GitDownloader { let mut update_origin_url = false; let mut output = String::new(); if self.inner.process.borrow_mut().execute_args( - &vec!["git".to_string(), "remote".to_string(), "-v".to_string()], + &["git".to_string(), "remote".to_string(), "-v".to_string()], &mut output, Some(path.clone()), ) == 0 @@ -1166,25 +1165,24 @@ impl VcsDownloader for GitDownloader { let path = self.normalize_path(path); let unpushed = self.get_unpushed_changes(package.clone(), &path)?; - if let Some(unpushed) = unpushed.as_deref() { - if self.inner.io.is_interactive() + if let Some(unpushed) = unpushed.as_deref() + && (self.inner.io.is_interactive() || self .inner .config .borrow_mut() .get("discard-changes") .as_bool() - != Some(true) - { - return Err(RuntimeException { - message: format!( - "Source directory {} has unpushed changes on the current branch: \n{}", - path, unpushed - ), - code: 0, - } - .into()); + != Some(true)) + { + return Err(RuntimeException { + message: format!( + "Source directory {} has unpushed changes on the current branch: \n{}", + path, unpushed + ), + code: 0, } + .into()); } let changes = match self.get_local_changes(package.clone(), &path)? { @@ -1337,7 +1335,7 @@ impl VcsDownloader for GitDownloader { ); let mut output = String::new(); if self.inner.process.borrow_mut().execute_args( - &vec!["git".to_string(), "stash".to_string(), "pop".to_string()], + &["git".to_string(), "stash".to_string(), "pop".to_string()], &mut output, Some(path.clone()), ) != 0 diff --git a/crates/shirabe/src/downloader/hg_downloader.rs b/crates/shirabe/src/downloader/hg_downloader.rs index a9a5bf8..59a4473 100644 --- a/crates/shirabe/src/downloader/hg_downloader.rs +++ b/crates/shirabe/src/downloader/hg_downloader.rs @@ -85,7 +85,7 @@ impl VcsDownloader for HgDownloader { ) -> Result<Option<PhpMixed>> { let hg_utils = HgUtils::new( self.inner.io.clone(), - &*self.inner.config.borrow(), + &self.inner.config.borrow(), &self.inner.process, ); @@ -140,7 +140,7 @@ impl VcsDownloader for HgDownloader { ) -> Result<Option<PhpMixed>> { let hg_utils = HgUtils::new( self.inner.io.clone(), - &*self.inner.config.borrow(), + &self.inner.config.borrow(), &self.inner.process, ); diff --git a/crates/shirabe/src/downloader/path_downloader.rs b/crates/shirabe/src/downloader/path_downloader.rs index 6d0e098..35c3709 100644 --- a/crates/shirabe/src/downloader/path_downloader.rs +++ b/crates/shirabe/src/downloader/path_downloader.rs @@ -135,7 +135,7 @@ impl PathDownloader { let mut allowed_strategies = vec![Self::STRATEGY_SYMLINK, Self::STRATEGY_MIRROR]; let mirror_path_repos = Platform::get_env("COMPOSER_MIRROR_PATH_REPOS"); - if mirror_path_repos.map_or(false, |v| !v.is_empty()) { + if mirror_path_repos.is_some_and(|v| !v.is_empty()) { current_strategy = Self::STRATEGY_MIRROR; } diff --git a/crates/shirabe/src/downloader/perforce_downloader.rs b/crates/shirabe/src/downloader/perforce_downloader.rs index 2d91c60..687b7ef 100644 --- a/crates/shirabe/src/downloader/perforce_downloader.rs +++ b/crates/shirabe/src/downloader/perforce_downloader.rs @@ -56,11 +56,10 @@ impl PerforceDownloader { let repository = package.get_repository(); let repo_config: Option<IndexMap<String, PhpMixed>> = if let Some(repo) = repository { let repo_ref = repo.borrow(); - if let Some(vcs_repo) = repo_ref.as_any().downcast_ref::<VcsRepository>() { - Some(self.get_repo_config(vcs_repo)) - } else { - None - } + repo_ref + .as_any() + .downcast_ref::<VcsRepository>() + .map(|vcs_repo| self.get_repo_config(vcs_repo)) } else { None }; diff --git a/crates/shirabe/src/downloader/svn_downloader.rs b/crates/shirabe/src/downloader/svn_downloader.rs index 03fd292..6aed27a 100644 --- a/crates/shirabe/src/downloader/svn_downloader.rs +++ b/crates/shirabe/src/downloader/svn_downloader.rs @@ -67,7 +67,7 @@ impl SvnDownloader { pub(crate) async fn discard_changes(&self, path: &str) -> anyhow::Result<Option<PhpMixed>> { let mut output = String::new(); if self.inner.process.borrow_mut().execute_args( - &["svn", "revert", "-R", "."].map(|s| s.to_string()).to_vec(), + ["svn", "revert", "-R", "."].map(|s| s.to_string()).as_ref(), &mut output, Some(path.to_string()), ) != 0 @@ -169,13 +169,12 @@ impl VcsDownloader for SvnDownloader { let repo_ref = repo.borrow(); if let Some(vcs_repo) = repo_ref.as_any().downcast_ref::<VcsRepository>() { let repo_config = vcs_repo.get_repo_config(); - if repo_config.contains_key("svn-cache-credentials") { - if let Some(val) = repo_config + if repo_config.contains_key("svn-cache-credentials") + && let Some(val) = repo_config .get("svn-cache-credentials") .and_then(|v| v.as_bool()) - { - self.cache_credentials = val; - } + { + self.cache_credentials = val; } } } @@ -412,8 +411,8 @@ impl VcsDownloader for SvnDownloader { }; // strip paths from references and only keep the actual revision - let from_revision = Preg::replace(r"{.*@(\d+)$}", "$1", &from_reference); - let to_revision = Preg::replace(r"{.*@(\d+)$}", "$1", &to_reference); + 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(), @@ -463,9 +462,9 @@ impl ChangeReportInterface for SvnDownloader { let mut output = String::new(); self.inner.process.borrow_mut().execute_args( - &["svn", "status", "--ignore-externals"] + ["svn", "status", "--ignore-externals"] .map(|s| s.to_string()) - .to_vec(), + .as_ref(), &mut output, Some(path.to_string()), ); diff --git a/crates/shirabe/src/downloader/vcs_downloader.rs b/crates/shirabe/src/downloader/vcs_downloader.rs index 18a50da..993d18a 100644 --- a/crates/shirabe/src/downloader/vcs_downloader.rs +++ b/crates/shirabe/src/downloader/vcs_downloader.rs @@ -165,14 +165,14 @@ pub trait VcsDownloader: true, io_interface::NORMAL, ); - } else if urls.len() > 0 { + } else if !urls.is_empty() { self.io().write_error3( " Failed, trying the next URL", true, io_interface::NORMAL, ); } - if urls.len() == 0 { + if urls.is_empty() { return Err(e); } } @@ -269,14 +269,14 @@ pub trait VcsDownloader: true, io_interface::NORMAL, ); - } else if urls.len() > 0 { + } else if !urls.is_empty() { self.io().write_error3( " Failed, trying the next URL", true, io_interface::NORMAL, ); } - if urls.len() == 0 { + if urls.is_empty() { return Err(e); } } @@ -338,7 +338,7 @@ pub trait VcsDownloader: true, io_interface::NORMAL, ); - } else if urls.len() > 0 { + } else if !urls.is_empty() { self.io().write_error3( " Failed, trying the next URL", true, @@ -358,12 +358,12 @@ pub trait VcsDownloader: let mut message = "Pulling in changes:"; let mut logs = self.get_commit_logs(&initial_ref, &target_ref, path)?; - if trim(&logs, None) == "" { + if trim(&logs, None).is_empty() { message = "Rolling back changes:"; logs = self.get_commit_logs(&target_ref, &initial_ref, path)?; } - if trim(&logs, None) != "" { + if !trim(&logs, None).is_empty() { let prefixed: Vec<String> = array_map( |line: &String| format!(" {}", line), &explode("\n", &logs), @@ -379,10 +379,10 @@ pub trait VcsDownloader: } } - if urls.is_empty() { - if let Some(e) = exception { - return Err(e); - } + if urls.is_empty() + && let Some(e) = exception + { + return Err(e); } Ok(None) diff --git a/crates/shirabe/src/downloader/xz_downloader.rs b/crates/shirabe/src/downloader/xz_downloader.rs index 1c03f1d..f7611fd 100644 --- a/crates/shirabe/src/downloader/xz_downloader.rs +++ b/crates/shirabe/src/downloader/xz_downloader.rs @@ -69,7 +69,7 @@ impl ArchiveDownloader for XzDownloader { file: &str, path: &str, ) -> Result<Option<PhpMixed>> { - let command = vec!["tar", "-xJf", file, "-C", path]; + let command = ["tar", "-xJf", file, "-C", path]; let mut ignored_output = PhpMixed::Null; if self.inner.process.borrow_mut().execute( diff --git a/crates/shirabe/src/downloader/zip_downloader.rs b/crates/shirabe/src/downloader/zip_downloader.rs index 2eb7b94..04e71b4 100644 --- a/crates/shirabe/src/downloader/zip_downloader.rs +++ b/crates/shirabe/src/downloader/zip_downloader.rs @@ -75,7 +75,7 @@ impl ZipDownloader { .lock() .unwrap() .as_ref() - .map_or(true, |v| v.is_empty()); + .is_none_or(|v| v.is_empty()); if unzip_commands_empty { return self.extract_with_zip_archive(package, file, path).await; } @@ -283,13 +283,10 @@ impl ZipDownloader { file: &str, path: &str, ) -> Result<Option<PhpMixed>> { - let mut zip_archive = self - .zip_archive_object - .take() - .unwrap_or_else(ZipArchive::new); + let mut zip_archive = self.zip_archive_object.take().unwrap_or_default(); let result: Result<Option<PhpMixed>> = (|| { - let retval = if !file_exists(file) || filesize(file).map_or(true, |s| s == 0) { + let retval = if !file_exists(file) || filesize(file).is_none_or(|s| s == 0) { Err(-1i64) } else { zip_archive.open(file, 0) @@ -323,16 +320,17 @@ impl ZipDownloader { } i += 1; } - if let Some(archive_sz) = archive_size { - if 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()); - } } } @@ -343,20 +341,20 @@ impl ZipDownloader { return Ok(None); } - return Err(RuntimeException { + 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()); + }.into()) } else { let code = retval.unwrap_err(); - return Err(UnexpectedValueException { + Err(UnexpectedValueException { message: self.get_error_message(code, file).trim_end().to_string(), code, } - .into()); + .into()) } })(); @@ -461,20 +459,19 @@ impl crate::downloader::DownloaderInterface for ZipDownloader { *unzip_commands = Some(vec![]); let finder = ExecutableFinder::new(); let commands = unzip_commands.as_mut().unwrap(); - if Platform::is_windows() { - if let Some(cmd) = + if Platform::is_windows() + && let Some(cmd) = finder.find("7z", None, &[r"C:\Program Files\7-Zip".to_string()]) - { - commands.push(vec![ - "7z".to_string(), - cmd, - "x".to_string(), - "-bb0".to_string(), - "-y".to_string(), - "%file%".to_string(), - "-o%path%".to_string(), - ]); - } + { + commands.push(vec![ + "7z".to_string(), + cmd, + "x".to_string(), + "-bb0".to_string(), + "-y".to_string(), + "%file%".to_string(), + "-o%path%".to_string(), + ]); } if let Some(cmd) = finder.find("unzip", None, &[]) { commands.push(vec