diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-05-22 23:14:27 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-05-23 15:48:00 +0900 |
| commit | 5adc4e467f01865ba2d4f519334ee1b0496b8ebf (patch) | |
| tree | f6970f181793c0f8b9b67b2af54c09ae13a25c4b /crates/shirabe/src/installer | |
| parent | 2a1696906344cb4da768a940bf8b1f89bbc82b47 (diff) | |
| download | php-shirabe-5adc4e467f01865ba2d4f519334ee1b0496b8ebf.tar.gz php-shirabe-5adc4e467f01865ba2d4f519334ee1b0496b8ebf.tar.zst php-shirabe-5adc4e467f01865ba2d4f519334ee1b0496b8ebf.zip | |
refactor(promise): change functions returning PromiseInterface to async fn
Diffstat (limited to 'crates/shirabe/src/installer')
| -rw-r--r-- | crates/shirabe/src/installer/installation_manager.rs | 18 | ||||
| -rw-r--r-- | crates/shirabe/src/installer/installer_interface.rs | 26 | ||||
| -rw-r--r-- | crates/shirabe/src/installer/library_installer.rs | 37 | ||||
| -rw-r--r-- | crates/shirabe/src/installer/metapackage_installer.rs | 27 | ||||
| -rw-r--r-- | crates/shirabe/src/installer/noop_installer.rs | 27 | ||||
| -rw-r--r-- | crates/shirabe/src/installer/plugin_installer.rs | 25 | ||||
| -rw-r--r-- | crates/shirabe/src/installer/project_installer.rs | 27 |
7 files changed, 89 insertions, 98 deletions
diff --git a/crates/shirabe/src/installer/installation_manager.rs b/crates/shirabe/src/installer/installation_manager.rs index 479e478..114f1fc 100644 --- a/crates/shirabe/src/installer/installation_manager.rs +++ b/crates/shirabe/src/installer/installation_manager.rs @@ -4,7 +4,6 @@ use crate::io::io_interface; use anyhow::Result; use indexmap::IndexMap; use shirabe_external_packages::react::promise; -use shirabe_external_packages::react::promise::PromiseInterface; use shirabe_external_packages::seld::signal::SignalHandler; use shirabe_php_shim::{ InvalidArgumentException, PhpMixed, array_search_mixed, array_splice, array_unshift, count, @@ -540,10 +539,7 @@ impl InstallationManager { /// Executes download operation. /// /// @phpstan-return PromiseInterface<void|null>|null - pub fn download( - &mut self, - package: &dyn PackageInterface, - ) -> Option<Box<dyn PromiseInterface>> { + pub async fn download(&mut self, package: &dyn PackageInterface) -> Option<PhpMixed> { let installer = self.get_installer(package.get_type()).ok()?; let promise = installer.cleanup("install", package, None).ok()?; @@ -553,11 +549,11 @@ impl InstallationManager { /// Executes install operation. /// /// @phpstan-return PromiseInterface<void|null>|null - pub fn install( + pub async fn install( &mut self, repo: &mut dyn InstalledRepositoryInterface, operation: &InstallOperation, - ) -> Option<Box<dyn PromiseInterface>> { + ) -> Option<PhpMixed> { let package = operation.get_package(); let installer = self.get_installer(package.get_type()).ok()?; let promise = installer.install(repo, package).ok()?; @@ -569,11 +565,11 @@ impl InstallationManager { /// Executes update operation. /// /// @phpstan-return PromiseInterface<void|null>|null - pub fn update( + pub async fn update( &mut self, repo: &mut dyn InstalledRepositoryInterface, operation: &UpdateOperation, - ) -> Option<Box<dyn PromiseInterface>> { + ) -> Option<PhpMixed> { let initial = operation.get_initial_package(); let target = operation.get_target_package(); @@ -608,11 +604,11 @@ impl InstallationManager { /// Uninstalls package. /// /// @phpstan-return PromiseInterface<void|null>|null - pub fn uninstall( + pub async fn uninstall( &mut self, repo: &mut dyn InstalledRepositoryInterface, operation: &UninstallOperation, - ) -> Option<Box<dyn PromiseInterface>> { + ) -> Option<PhpMixed> { let package = operation.get_package(); let installer = self.get_installer(package.get_type()).ok()?; diff --git a/crates/shirabe/src/installer/installer_interface.rs b/crates/shirabe/src/installer/installer_interface.rs index 5370364..29171cf 100644 --- a/crates/shirabe/src/installer/installer_interface.rs +++ b/crates/shirabe/src/installer/installer_interface.rs @@ -2,7 +2,7 @@ use crate::package::PackageInterface; use crate::repository::InstalledRepositoryInterface; -use shirabe_external_packages::react::promise::PromiseInterface; +use shirabe_php_shim::PhpMixed; pub trait InstallerInterface: std::fmt::Debug { fn supports(&self, package_type: &str) -> bool; @@ -13,44 +13,44 @@ pub trait InstallerInterface: std::fmt::Debug { package: &dyn PackageInterface, ) -> bool; - fn download( + async fn download( &self, package: &dyn PackageInterface, prev_package: Option<&dyn PackageInterface>, - ) -> anyhow::Result<Option<Box<dyn PromiseInterface>>>; + ) -> anyhow::Result<Option<PhpMixed>>; - fn prepare( + async fn prepare( &self, r#type: &str, package: &dyn PackageInterface, prev_package: Option<&dyn PackageInterface>, - ) -> anyhow::Result<Option<Box<dyn PromiseInterface>>>; + ) -> anyhow::Result<Option<PhpMixed>>; - fn install( + async fn install( &mut self, repo: &mut dyn InstalledRepositoryInterface, package: &dyn PackageInterface, - ) -> anyhow::Result<Option<Box<dyn PromiseInterface>>>; + ) -> anyhow::Result<Option<PhpMixed>>; - fn update( + async fn update( &mut self, repo: &mut dyn InstalledRepositoryInterface, initial: &dyn PackageInterface, target: &dyn PackageInterface, - ) -> anyhow::Result<Option<Box<dyn PromiseInterface>>>; + ) -> anyhow::Result<Option<PhpMixed>>; - fn uninstall( + async fn uninstall( &mut self, repo: &mut dyn InstalledRepositoryInterface, package: &dyn PackageInterface, - ) -> anyhow::Result<Option<Box<dyn PromiseInterface>>>; + ) -> anyhow::Result<Option<PhpMixed>>; - fn cleanup( + async fn cleanup( &self, r#type: &str, package: &dyn PackageInterface, prev_package: Option<&dyn PackageInterface>, - ) -> anyhow::Result<Option<Box<dyn PromiseInterface>>>; + ) -> anyhow::Result<Option<PhpMixed>>; fn get_install_path(&self, package: &dyn PackageInterface) -> Option<String>; diff --git a/crates/shirabe/src/installer/library_installer.rs b/crates/shirabe/src/installer/library_installer.rs index 4c3f201..a9a77e9 100644 --- a/crates/shirabe/src/installer/library_installer.rs +++ b/crates/shirabe/src/installer/library_installer.rs @@ -4,7 +4,6 @@ use std::any::Any; use anyhow::Result; use shirabe_external_packages::composer::pcre::Preg; -use shirabe_external_packages::react::promise::PromiseInterface; use shirabe_php_shim::{ InvalidArgumentException, LogicException, is_link, preg_quote, realpath, rmdir, rtrim, strpos, }; @@ -132,10 +131,10 @@ impl LibraryInstaller { /// @return PromiseInterface|null /// @phpstan-return PromiseInterface<void|null>|null - pub(crate) fn install_code( + pub(crate) async fn install_code( &self, package: &dyn PackageInterface, - ) -> Result<Option<Box<dyn PromiseInterface>>> { + ) -> Result<Option<PhpMixed>> { let download_path = self.get_install_path(package).unwrap(); Ok(Some( @@ -147,11 +146,11 @@ impl LibraryInstaller { /// @return PromiseInterface|null /// @phpstan-return PromiseInterface<void|null>|null - pub(crate) fn update_code( + pub(crate) async fn update_code( &self, initial: &dyn PackageInterface, target: &dyn PackageInterface, - ) -> Result<Option<Box<dyn PromiseInterface>>> { + ) -> Result<Option<PhpMixed>> { let initial_download_path = self.get_install_path(initial).unwrap(); let target_download_path = self.get_install_path(target).unwrap(); if target_download_path != initial_download_path { @@ -189,10 +188,10 @@ impl LibraryInstaller { /// @return PromiseInterface|null /// @phpstan-return PromiseInterface<void|null>|null - pub(crate) fn remove_code( + pub(crate) async fn remove_code( &self, package: &dyn PackageInterface, - ) -> Result<Option<Box<dyn PromiseInterface>>> { + ) -> Result<Option<PhpMixed>> { let download_path = self.get_package_base_path(package); Ok(Some( @@ -267,11 +266,11 @@ impl InstallerInterface for LibraryInstaller { false } - fn download( + async fn download( &self, package: &dyn PackageInterface, prev_package: Option<&dyn PackageInterface>, - ) -> Result<Option<Box<dyn PromiseInterface>>> { + ) -> Result<Option<PhpMixed>> { // TODO(phase-b): initialize_vendor_dir requires &mut self // self.initialize_vendor_dir(); let download_path = self.get_install_path(package).unwrap(); @@ -283,12 +282,12 @@ impl InstallerInterface for LibraryInstaller { )?)) } - fn prepare( + async fn prepare( &self, r#type: &str, package: &dyn PackageInterface, prev_package: Option<&dyn PackageInterface>, - ) -> Result<Option<Box<dyn PromiseInterface>>> { + ) -> Result<Option<PhpMixed>> { // TODO(phase-b): initialize_vendor_dir requires &mut self // self.initialize_vendor_dir(); let download_path = self.get_install_path(package).unwrap(); @@ -301,12 +300,12 @@ impl InstallerInterface for LibraryInstaller { )?)) } - fn cleanup( + async fn cleanup( &self, r#type: &str, package: &dyn PackageInterface, prev_package: Option<&dyn PackageInterface>, - ) -> Result<Option<Box<dyn PromiseInterface>>> { + ) -> Result<Option<PhpMixed>> { // TODO(phase-b): initialize_vendor_dir requires &mut self // self.initialize_vendor_dir(); let download_path = self.get_install_path(package).unwrap(); @@ -319,11 +318,11 @@ impl InstallerInterface for LibraryInstaller { )?)) } - fn install( + async fn install( &mut self, repo: &mut dyn InstalledRepositoryInterface, package: &dyn PackageInterface, - ) -> Result<Option<Box<dyn PromiseInterface>>> { + ) -> Result<Option<PhpMixed>> { // TODO(phase-b): initialize_vendor_dir requires &mut self // self.initialize_vendor_dir(); let download_path = self.get_install_path(package).unwrap(); @@ -348,12 +347,12 @@ impl InstallerInterface for LibraryInstaller { ))) } - fn update( + async fn update( &mut self, repo: &mut dyn InstalledRepositoryInterface, initial: &dyn PackageInterface, target: &dyn PackageInterface, - ) -> Result<Option<Box<dyn PromiseInterface>>> { + ) -> Result<Option<PhpMixed>> { if !repo.has_package(initial) { return Err(InvalidArgumentException { message: format!("Package is not installed: {}", initial), @@ -381,11 +380,11 @@ impl InstallerInterface for LibraryInstaller { ))) } - fn uninstall( + async fn uninstall( &mut self, repo: &mut dyn InstalledRepositoryInterface, package: &dyn PackageInterface, - ) -> Result<Option<Box<dyn PromiseInterface>>> { + ) -> Result<Option<PhpMixed>> { if !repo.has_package(package) { return Err(InvalidArgumentException { message: format!("Package is not installed: {}", package), diff --git a/crates/shirabe/src/installer/metapackage_installer.rs b/crates/shirabe/src/installer/metapackage_installer.rs index 2c23229..f6d6133 100644 --- a/crates/shirabe/src/installer/metapackage_installer.rs +++ b/crates/shirabe/src/installer/metapackage_installer.rs @@ -9,8 +9,7 @@ use crate::io::io_interface; use crate::package::PackageInterface; use crate::repository::InstalledRepositoryInterface; use anyhow::Result; -use shirabe_external_packages::react::promise::PromiseInterface; -use shirabe_php_shim::InvalidArgumentException; +use shirabe_php_shim::{InvalidArgumentException, PhpMixed}; #[derive(Debug)] pub struct MetapackageInstaller { @@ -36,43 +35,43 @@ impl InstallerInterface for MetapackageInstaller { repo.has_package(package) } - fn download( + async fn download( &self, _package: &dyn PackageInterface, _prev_package: Option<&dyn PackageInterface>, - ) -> Result<Option<Box<dyn PromiseInterface>>> { + ) -> Result<Option<PhpMixed>> { Ok(Some(shirabe_external_packages::react::promise::resolve( None, ))) } - fn prepare( + async fn prepare( &self, _type: &str, _package: &dyn PackageInterface, _prev_package: Option<&dyn PackageInterface>, - ) -> Result<Option<Box<dyn PromiseInterface>>> { + ) -> Result<Option<PhpMixed>> { Ok(Some(shirabe_external_packages::react::promise::resolve( None, ))) } - fn cleanup( + async fn cleanup( &self, _type: &str, _package: &dyn PackageInterface, _prev_package: Option<&dyn PackageInterface>, - ) -> Result<Option<Box<dyn PromiseInterface>>> { + ) -> Result<Option<PhpMixed>> { Ok(Some(shirabe_external_packages::react::promise::resolve( None, ))) } - fn install( + async fn install( &mut self, repo: &mut dyn InstalledRepositoryInterface, package: &dyn PackageInterface, - ) -> Result<Option<Box<dyn PromiseInterface>>> { + ) -> Result<Option<PhpMixed>> { self.io.write_error3( &format!(" - {}", InstallOperation::format(package, false)), true, @@ -86,12 +85,12 @@ impl InstallerInterface for MetapackageInstaller { ))) } - fn update( + async fn update( &mut self, repo: &mut dyn InstalledRepositoryInterface, initial: &dyn PackageInterface, target: &dyn PackageInterface, - ) -> Result<Option<Box<dyn PromiseInterface>>> { + ) -> Result<Option<PhpMixed>> { if !repo.has_package(initial) { return Err(InvalidArgumentException { message: format!("Package is not installed: {}", initial), @@ -114,11 +113,11 @@ impl InstallerInterface for MetapackageInstaller { ))) } - fn uninstall( + async fn uninstall( &mut self, repo: &mut dyn InstalledRepositoryInterface, package: &dyn PackageInterface, - ) -> Result<Option<Box<dyn PromiseInterface>>> { + ) -> Result<Option<PhpMixed>> { if !repo.has_package(package) { return Err(InvalidArgumentException { message: format!("Package is not installed: {}", package), diff --git a/crates/shirabe/src/installer/noop_installer.rs b/crates/shirabe/src/installer/noop_installer.rs index 360f962..263caca 100644 --- a/crates/shirabe/src/installer/noop_installer.rs +++ b/crates/shirabe/src/installer/noop_installer.rs @@ -3,8 +3,7 @@ use crate::installer::InstallerInterface; use crate::package::PackageInterface; use crate::repository::InstalledRepositoryInterface; -use shirabe_external_packages::react::promise::PromiseInterface; -use shirabe_php_shim::InvalidArgumentException; +use shirabe_php_shim::{InvalidArgumentException, PhpMixed}; #[derive(Debug)] pub struct NoopInstaller; @@ -22,43 +21,43 @@ impl InstallerInterface for NoopInstaller { repo.has_package(package) } - fn download( + async fn download( &self, _package: &dyn PackageInterface, _prev_package: Option<&dyn PackageInterface>, - ) -> anyhow::Result<Option<Box<dyn PromiseInterface>>> { + ) -> anyhow::Result<Option<PhpMixed>> { Ok(Some(shirabe_external_packages::react::promise::resolve( None, ))) } - fn prepare( + async fn prepare( &self, _type: &str, _package: &dyn PackageInterface, _prev_package: Option<&dyn PackageInterface>, - ) -> anyhow::Result<Option<Box<dyn PromiseInterface>>> { + ) -> anyhow::Result<Option<PhpMixed>> { Ok(Some(shirabe_external_packages::react::promise::resolve( None, ))) } - fn cleanup( + async fn cleanup( &self, _type: &str, _package: &dyn PackageInterface, _prev_package: Option<&dyn PackageInterface>, - ) -> anyhow::Result<Option<Box<dyn PromiseInterface>>> { + ) -> anyhow::Result<Option<PhpMixed>> { Ok(Some(shirabe_external_packages::react::promise::resolve( None, ))) } - fn install( + async fn install( &mut self, repo: &mut dyn InstalledRepositoryInterface, package: &dyn PackageInterface, - ) -> anyhow::Result<Option<Box<dyn PromiseInterface>>> { + ) -> anyhow::Result<Option<PhpMixed>> { if !repo.has_package(package) { repo.add_package(package.clone_package_box()); } @@ -68,12 +67,12 @@ impl InstallerInterface for NoopInstaller { ))) } - fn update( + async fn update( &mut self, repo: &mut dyn InstalledRepositoryInterface, initial: &dyn PackageInterface, target: &dyn PackageInterface, - ) -> anyhow::Result<Option<Box<dyn PromiseInterface>>> { + ) -> anyhow::Result<Option<PhpMixed>> { if !repo.has_package(initial) { return Err(InvalidArgumentException { message: format!("Package is not installed: {}", initial), @@ -92,11 +91,11 @@ impl InstallerInterface for NoopInstaller { ))) } - fn uninstall( + async fn uninstall( &mut self, repo: &mut dyn InstalledRepositoryInterface, package: &dyn PackageInterface, - ) -> anyhow::Result<Option<Box<dyn PromiseInterface>>> { + ) -> anyhow::Result<Option<PhpMixed>> { if !repo.has_package(package) { return Err(InvalidArgumentException { message: format!("Package is not installed: {}", package), diff --git a/crates/shirabe/src/installer/plugin_installer.rs b/crates/shirabe/src/installer/plugin_installer.rs index e1d4c5e..fd1fc99 100644 --- a/crates/shirabe/src/installer/plugin_installer.rs +++ b/crates/shirabe/src/installer/plugin_installer.rs @@ -11,7 +11,6 @@ use crate::repository::InstalledRepositoryInterface; use crate::util::Filesystem; use crate::util::Platform; use anyhow::Result; -use shirabe_external_packages::react::promise::PromiseInterface; use shirabe_php_shim::{LogicException, PhpMixed, UnexpectedValueException, empty}; #[derive(Debug)] @@ -75,12 +74,12 @@ impl InstallerInterface for PluginInstaller { self.inner.is_installed(repo, package) } - fn prepare( + async fn prepare( &self, r#type: &str, package: &dyn PackageInterface, prev_package: Option<&dyn PackageInterface>, - ) -> Result<Option<Box<dyn PromiseInterface>>> { + ) -> Result<Option<PhpMixed>> { if (r#type == "install" || r#type == "update") && !self .get_plugin_manager() @@ -100,11 +99,11 @@ impl InstallerInterface for PluginInstaller { self.inner.prepare(r#type, package, prev_package) } - fn download( + async fn download( &self, package: &dyn PackageInterface, prev_package: Option<&dyn PackageInterface>, - ) -> Result<Option<Box<dyn PromiseInterface>>> { + ) -> Result<Option<PhpMixed>> { let extra = package.get_extra(); let class = extra.get("class").cloned().unwrap_or(PhpMixed::Null); if empty(&class) { @@ -120,11 +119,11 @@ impl InstallerInterface for PluginInstaller { self.inner.download(package, prev_package) } - fn install( + async fn install( &mut self, repo: &mut dyn InstalledRepositoryInterface, package: &dyn PackageInterface, - ) -> Result<Option<Box<dyn PromiseInterface>>> { + ) -> Result<Option<PhpMixed>> { let promise = self.inner.install(repo, package)?; let promise = match promise { Some(p) => p, @@ -143,12 +142,12 @@ impl InstallerInterface for PluginInstaller { ))) } - fn update( + async fn update( &mut self, repo: &mut dyn InstalledRepositoryInterface, initial: &dyn PackageInterface, target: &dyn PackageInterface, - ) -> Result<Option<Box<dyn PromiseInterface>>> { + ) -> Result<Option<PhpMixed>> { let promise = self.inner.update(repo, initial, target)?; let promise = match promise { Some(p) => p, @@ -168,11 +167,11 @@ impl InstallerInterface for PluginInstaller { ))) } - fn uninstall( + async fn uninstall( &mut self, repo: &mut dyn InstalledRepositoryInterface, package: &dyn PackageInterface, - ) -> Result<Option<Box<dyn PromiseInterface>>> { + ) -> Result<Option<PhpMixed>> { // TODO(plugin): uninstall package from plugin manager self.get_plugin_manager() .borrow_mut() @@ -181,12 +180,12 @@ impl InstallerInterface for PluginInstaller { self.inner.uninstall(repo, package) } - fn cleanup( + async fn cleanup( &self, r#type: &str, package: &dyn PackageInterface, prev_package: Option<&dyn PackageInterface>, - ) -> Result<Option<Box<dyn PromiseInterface>>> { + ) -> Result<Option<PhpMixed>> { self.inner.cleanup(r#type, package, prev_package) } diff --git a/crates/shirabe/src/installer/project_installer.rs b/crates/shirabe/src/installer/project_installer.rs index ad2c3a6..1c50a16 100644 --- a/crates/shirabe/src/installer/project_installer.rs +++ b/crates/shirabe/src/installer/project_installer.rs @@ -5,8 +5,7 @@ use crate::installer::InstallerInterface; use crate::package::PackageInterface; use crate::repository::InstalledRepositoryInterface; use crate::util::Filesystem; -use shirabe_external_packages::react::promise::PromiseInterface; -use shirabe_php_shim::InvalidArgumentException; +use shirabe_php_shim::{InvalidArgumentException, PhpMixed}; #[derive(Debug)] pub struct ProjectInstaller { @@ -43,11 +42,11 @@ impl InstallerInterface for ProjectInstaller { false } - fn download( + async fn download( &self, package: &dyn PackageInterface, prev_package: Option<&dyn PackageInterface>, - ) -> anyhow::Result<Option<Box<dyn PromiseInterface>>> { + ) -> anyhow::Result<Option<PhpMixed>> { let install_path = &self.install_path; if std::path::Path::new(install_path).exists() && !self.filesystem.borrow().is_dir_empty(install_path) @@ -68,35 +67,35 @@ impl InstallerInterface for ProjectInstaller { .map(Some) } - fn prepare( + async fn prepare( &self, r#type: &str, package: &dyn PackageInterface, prev_package: Option<&dyn PackageInterface>, - ) -> anyhow::Result<Option<Box<dyn PromiseInterface>>> { + ) -> anyhow::Result<Option<PhpMixed>> { self.download_manager .borrow() .prepare(r#type, package, &self.install_path, prev_package) .map(Some) } - fn cleanup( + async fn cleanup( &self, r#type: &str, package: &dyn PackageInterface, prev_package: Option<&dyn PackageInterface>, - ) -> anyhow::Result<Option<Box<dyn PromiseInterface>>> { + ) -> anyhow::Result<Option<PhpMixed>> { self.download_manager .borrow() .cleanup(r#type, package, &self.install_path, prev_package) .map(Some) } - fn install( + async fn install( &mut self, _repo: &mut dyn InstalledRepositoryInterface, package: &dyn PackageInterface, - ) -> anyhow::Result<Option<Box<dyn PromiseInterface>>> { + ) -> anyhow::Result<Option<PhpMixed>> { Ok(Some( self.download_manager .borrow() @@ -104,12 +103,12 @@ impl InstallerInterface for ProjectInstaller { )) } - fn update( + async fn update( &mut self, _repo: &mut dyn InstalledRepositoryInterface, _initial: &dyn PackageInterface, _target: &dyn PackageInterface, - ) -> anyhow::Result<Option<Box<dyn PromiseInterface>>> { + ) -> anyhow::Result<Option<PhpMixed>> { Err(InvalidArgumentException { message: "not supported".to_string(), code: 0, @@ -117,11 +116,11 @@ impl InstallerInterface for ProjectInstaller { .into()) } - fn uninstall( + async fn uninstall( &mut self, _repo: &mut dyn InstalledRepositoryInterface, _package: &dyn PackageInterface, - ) -> anyhow::Result<Option<Box<dyn PromiseInterface>>> { + ) -> anyhow::Result<Option<PhpMixed>> { Err(InvalidArgumentException { message: "not supported".to_string(), code: 0, |
