From 37f10618689c55d651028487c39988fedcb593ea Mon Sep 17 00:00:00 2001 From: nsfisis Date: Wed, 3 Jun 2026 00:46:13 +0900 Subject: feat(installer): wire OperationInterface instanceof downcasts in batches Resolve the UpdateOperation/InstallOperation batch-splitting checks and the markAliasInstalled/markAliasUninstalled dispatch in InstallationManager using the existing as_update_operation/as_install_operation accessors and as_any downcasts to the MarkAlias operation types. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../shirabe/src/installer/installation_manager.rs | 75 ++++++++++++++-------- 1 file changed, 50 insertions(+), 25 deletions(-) diff --git a/crates/shirabe/src/installer/installation_manager.rs b/crates/shirabe/src/installer/installation_manager.rs index 578a61e..b95ad26 100644 --- a/crates/shirabe/src/installer/installation_manager.rs +++ b/crates/shirabe/src/installer/installation_manager.rs @@ -208,25 +208,32 @@ impl InstallationManager { let mut batch: IndexMap> = IndexMap::new(); for (index, operation) in operations.into_iter().enumerate() { let index = index as i64; - // TODO(phase-b): instanceof downcasts for UpdateOperation/InstallOperation - let is_update_or_install = false; - if is_update_or_install { - let package: Option = None; - let _ = package; - let extra: IndexMap = IndexMap::new(); - if extra - .get("plugin-modifies-downloads") - .and_then(|v| v.as_bool()) - == Some(true) - { - if (batch.len() as i64) > 0 { - batches.push(std::mem::take(&mut batch)); + // PHP: $operation instanceof UpdateOperation || $operation instanceof InstallOperation + let package: Option = + if let Some(update) = operation.as_update_operation() { + Some(update.get_target_package()) + } else { + operation + .as_install_operation() + .map(|install| install.get_package()) + }; + if let Some(package) = package { + if package.get_type() == "composer-plugin" { + let extra = package.get_extra(); + if extra + .get("plugin-modifies-downloads") + .and_then(|v| v.as_bool()) + == Some(true) + { + if (batch.len() as i64) > 0 { + batches.push(std::mem::take(&mut batch)); + } + let mut single = IndexMap::new(); + single.insert(index, operation); + batches.push(single); + + continue; } - let mut single = IndexMap::new(); - single.insert(index, operation); - batches.push(single); - - continue; } } batch.insert(index, operation); @@ -360,11 +367,17 @@ impl InstallationManager { let mut batches: Vec>> = vec![]; let mut batch: IndexMap> = IndexMap::new(); for (index, operation) in operations { - // TODO(phase-b): instanceof InstallOperation/UpdateOperation downcasts - let is_install_or_update = false; - if is_install_or_update { - // TODO(phase-b): package type check (composer-plugin / composer-installer) - let pkg_type = ""; + // PHP: $operation instanceof InstallOperation || $operation instanceof UpdateOperation + let package: Option = + if let Some(update) = operation.as_update_operation() { + Some(update.get_target_package()) + } else { + operation + .as_install_operation() + .map(|install| install.get_package()) + }; + if let Some(package) = package { + let pkg_type = package.get_type(); if pkg_type == "composer-plugin" || pkg_type == "composer-installer" { if (batch.len() as i64) > 0 { batches.push(std::mem::take(&mut batch)); @@ -434,10 +447,22 @@ impl InstallationManager { // PHP: $this->{$opType}($repo, $operation); match op_type.as_str() { "markAliasInstalled" => { - // TODO(phase-b): downcast operation to MarkAliasInstalledOperation + let op = operation + .as_any() + .downcast_ref::() + .expect( + "op_type == \"markAliasInstalled\" implies MarkAliasInstalledOperation", + ); + self.mark_alias_installed(repo, op); } "markAliasUninstalled" => { - // TODO(phase-b): downcast operation to MarkAliasUninstalledOperation + let op = operation + .as_any() + .downcast_ref::() + .expect( + "op_type == \"markAliasUninstalled\" implies MarkAliasUninstalledOperation", + ); + self.mark_alias_uninstalled(repo, op); } _ => {} } -- cgit v1.3.1