diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-05-23 15:45:33 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-05-23 15:48:00 +0900 |
| commit | bd6d0186d2c01a3e1d6324ad5a0bcdd71de53098 (patch) | |
| tree | 939eb1dccbfb3341a2f618e734ca23ef84a8e5cc /crates/shirabe/src/installer/library_installer.rs | |
| parent | e068a9d644fde6659a88accd55b3f1d0d9d7cf46 (diff) | |
| download | php-shirabe-bd6d0186d2c01a3e1d6324ad5a0bcdd71de53098.tar.gz php-shirabe-bd6d0186d2c01a3e1d6324ad5a0bcdd71de53098.tar.zst php-shirabe-bd6d0186d2c01a3e1d6324ad5a0bcdd71de53098.zip | |
refactor(promise): drop \React\Promise
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/installer/library_installer.rs')
| -rw-r--r-- | crates/shirabe/src/installer/library_installer.rs | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/crates/shirabe/src/installer/library_installer.rs b/crates/shirabe/src/installer/library_installer.rs index 0629de5..29cb455 100644 --- a/crates/shirabe/src/installer/library_installer.rs +++ b/crates/shirabe/src/installer/library_installer.rs @@ -5,7 +5,8 @@ use std::any::Any; use anyhow::Result; use shirabe_external_packages::composer::pcre::Preg; use shirabe_php_shim::{ - InvalidArgumentException, LogicException, is_link, preg_quote, realpath, rmdir, rtrim, strpos, + InvalidArgumentException, LogicException, PhpMixed, dirname, is_dir, is_link, preg_quote, + realpath, rmdir, rtrim, strpos, }; use crate::composer::PartialComposerWeakHandle; @@ -215,6 +216,7 @@ impl LibraryInstaller { } } +#[async_trait::async_trait(?Send)] impl InstallerInterface for LibraryInstaller { fn supports(&self, package_type: &str) -> bool { match &self.r#type { @@ -314,20 +316,16 @@ impl InstallerInterface for LibraryInstaller { self.binary_installer.remove_binaries(package); } - // TODO(phase-c-promise): rewrite install_code().then(installBinaries + repo.addPackage) as an await sequence. - let promise = self.install_code(package)?; - let promise = match promise { - Some(p) => p, - None => shirabe_external_packages::react::promise::resolve(None), - }; + let _ = self.install_code(package).await?; - // TODO(phase-b): promise.then expects Option<Box<dyn FnOnce(Option<PhpMixed>) -> Option<PhpMixed>>> - // arguments. The original PHP closure captures &mut self/binary_installer/repo/package; - // restructuring required. - let _ = promise; - Ok(Some(todo!( - "promise.then(...) chain to install_binaries + repo.add_package" - ))) + let install_path = self.get_install_path(package).unwrap(); + self.binary_installer + .install_binaries(package, &install_path, true); + if !repo.has_package(package) { + repo.add_package(package.clone_package_box()); + } + + Ok(None) } async fn update( @@ -348,20 +346,17 @@ impl InstallerInterface for LibraryInstaller { // self.initialize_vendor_dir(); self.binary_installer.remove_binaries(initial); - // TODO(phase-c-promise): rewrite update_code().then(installBinaries + repo updates) as an await sequence. - let promise = self.update_code(initial, target)?; - let promise = match promise { - Some(p) => p, - None => shirabe_external_packages::react::promise::resolve(None), - }; + let _ = self.update_code(initial, target).await?; + + let install_path = self.get_install_path(target).unwrap(); + self.binary_installer + .install_binaries(target, &install_path, true); + repo.remove_package(initial); + if !repo.has_package(target) { + repo.add_package(target.clone_package_box()); + } - // TODO(phase-b): promise.then expects Option<Box<dyn FnOnce(Option<PhpMixed>) -> Option<PhpMixed>>> - // arguments. Closure captures &mut self/binary_installer/repo/initial/target; - // restructuring required. - let _ = promise; - Ok(Some(todo!( - "promise.then(...) chain to install_binaries + repo updates" - ))) + Ok(None) } async fn uninstall( @@ -377,20 +372,25 @@ impl InstallerInterface for LibraryInstaller { .into()); } - // TODO(phase-c-promise): rewrite remove_code().then(remove_binaries/remove_package/rmdir) as an await sequence. - let promise = self.remove_code(package)?; - let promise = match promise { - Some(p) => p, - None => shirabe_external_packages::react::promise::resolve(None), - }; + let _ = self.remove_code(package).await?; + + let download_path = self.get_package_base_path(package); + self.binary_installer.remove_binaries(package); + repo.remove_package(package); + + if strpos(package.get_name(), "/").map_or(false, |pos| pos != 0) { + let package_vendor_dir = dirname(&download_path); + if is_dir(&package_vendor_dir) + && self.filesystem.borrow().is_dir_empty(&package_vendor_dir) + { + let _ = Silencer::call(|| { + rmdir(&package_vendor_dir); + Ok(()) + }); + } + } - // TODO(phase-b): promise.then expects Option<Box<dyn FnOnce(Option<PhpMixed>) -> Option<PhpMixed>>> - // arguments. Closure captures binary_installer/filesystem/download_path/package/repo; - // restructuring required. - let _ = promise; - Ok(Some(todo!( - "promise.then(...) chain to remove_binaries/remove_package/rmdir" - ))) + Ok(None) } fn get_install_path(&self, package: &dyn PackageInterface) -> Option<String> { |
