aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/installer/installation_manager.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-02 08:42:55 +0900
committernsfisis <nsfisis@gmail.com>2026-08-02 08:42:55 +0900
commitb5d6d91054b9ceef95aef0819bb5c4ef7db1abdd (patch)
tree0bd12e599f48fcc63375363363416ca48766c698 /crates/shirabe/src/installer/installation_manager.rs
parent3e367f78eec3521106979461fda717926717515a (diff)
downloadphp-shirabe-b5d6d91054b9ceef95aef0819bb5c4ef7db1abdd.tar.gz
php-shirabe-b5d6d91054b9ceef95aef0819bb5c4ef7db1abdd.tar.zst
php-shirabe-b5d6d91054b9ceef95aef0819bb5c4ef7db1abdd.zip
fix(repository): run lazy initialization in count/has_package
PHP's ArrayRepository::count()/hasPackage() call $this->initialize(), which late-binds to the concrete repository class and lazily loads its packages. The Rust pass-throughs skipped that: they ran ArrayRepository's stub initialize instead, returning 0/false and marking the repository initialized with an empty package list, which made ensure_initialized() skip the real initialization forever after. Take &mut self in RepositoryInterface::count/has_package so the lazy repositories (Filesystem, Platform, Composer) can guard with their real initialize, and return Result from has_package since that initialization can fail (PHP propagates the exception). InstallerInterface::is_installed and InstallationManager::is_package_installed/mark_alias_installed propagate the same way, which also resolves the TODO(phase-d) markers on Package/Path/Artifact/Vcs repositories about initialization errors being swallowed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/installer/installation_manager.rs')
-rw-r--r--crates/shirabe/src/installer/installation_manager.rs27
1 files changed, 14 insertions, 13 deletions
diff --git a/crates/shirabe/src/installer/installation_manager.rs b/crates/shirabe/src/installer/installation_manager.rs
index 9517eada..3a04a8e9 100644
--- a/crates/shirabe/src/installer/installation_manager.rs
+++ b/crates/shirabe/src/installer/installation_manager.rs
@@ -198,22 +198,21 @@ impl InstallationManager {
/// Checks whether provided package is installed in one of the registered installers.
pub fn is_package_installed(
&self,
- repo: &dyn InstalledRepositoryInterface,
+ repo: &mut dyn InstalledRepositoryInterface,
package: PackageInterfaceHandle,
) -> anyhow::Result<bool> {
// For testing only (ref InstallationManagerMock::isPackageInstalled).
if self.mock.is_some() {
- return Ok(repo.has_package(package));
+ return repo.has_package(package);
}
if let Some(alias) = package.as_alias() {
let alias_of: PackageInterfaceHandle = alias.get_alias_of().into();
- return Ok(repo.has_package(package) && self.is_package_installed(repo, alias_of)?);
+ return Ok(repo.has_package(package)? && self.is_package_installed(repo, alias_of)?);
}
- Ok(self
- .get_installer(&package.get_type())?
- .is_installed(repo, package))
+ self.get_installer(&package.get_type())?
+ .is_installed(repo, package)
}
/// Install binary for the given package.
@@ -264,7 +263,7 @@ impl InstallationManager {
mock.updated.push((initial.clone(), target.clone()));
mock.trace.push(trace);
repo.remove_package(initial);
- if !repo.has_package(target.clone()) {
+ if !repo.has_package(target.clone())? {
repo.add_package(PackageInterfaceHandle::dup(&target));
}
}
@@ -278,7 +277,7 @@ impl InstallationManager {
let package: PackageInterfaceHandle = op.get_package().into();
mock.installed.push(package.clone());
mock.trace.push(trace);
- if !repo.has_package(package.clone()) {
+ if !repo.has_package(package.clone())? {
repo.add_package(PackageInterfaceHandle::dup(&package));
}
}
@@ -578,7 +577,7 @@ impl InstallationManager {
}
match &operation {
AnyOperation::MarkAliasInstalled(op) => {
- self.mark_alias_installed(&mut **repo.borrow_mut(), op);
+ self.mark_alias_installed(&mut **repo.borrow_mut(), op)?;
}
AnyOperation::MarkAliasUninstalled(op) => {
self.mark_alias_uninstalled(&mut **repo.borrow_mut(), op);
@@ -760,12 +759,14 @@ impl InstallationManager {
&self,
repo: &mut dyn InstalledRepositoryInterface,
operation: &MarkAliasInstalledOperation,
- ) {
+ ) -> anyhow::Result<()> {
let package = operation.get_package();
- if !repo.has_package(package.clone().into()) {
+ if !repo.has_package(package.clone().into())? {
repo.add_package(crate::package::PackageInterfaceHandle::dup(&package.into()));
}
+
+ Ok(())
}
/// Executes markAlias operation.
@@ -1016,7 +1017,7 @@ pub trait InstallationManagerInterface: std::fmt::Debug {
fn disable_plugins(&mut self);
fn is_package_installed(
&mut self,
- repo: &dyn InstalledRepositoryInterface,
+ repo: &mut dyn InstalledRepositoryInterface,
package: PackageInterfaceHandle,
) -> anyhow::Result<bool>;
fn ensure_binaries_presence(&mut self, package: PackageInterfaceHandle);
@@ -1052,7 +1053,7 @@ impl InstallationManagerInterface for InstallationManager {
fn is_package_installed(
&mut self,
- repo: &dyn InstalledRepositoryInterface,
+ repo: &mut dyn InstalledRepositoryInterface,
package: PackageInterfaceHandle,
) -> anyhow::Result<bool> {
InstallationManager::is_package_installed(self, repo, package)