diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-02 08:42:55 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-02 08:42:55 +0900 |
| commit | b5d6d91054b9ceef95aef0819bb5c4ef7db1abdd (patch) | |
| tree | 0bd12e599f48fcc63375363363416ca48766c698 /crates/shirabe/src/repository/composer_repository.rs | |
| parent | 3e367f78eec3521106979461fda717926717515a (diff) | |
| download | php-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/repository/composer_repository.rs')
| -rw-r--r-- | crates/shirabe/src/repository/composer_repository.rs | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/crates/shirabe/src/repository/composer_repository.rs b/crates/shirabe/src/repository/composer_repository.rs index 558d7e00..ba68d22c 100644 --- a/crates/shirabe/src/repository/composer_repository.rs +++ b/crates/shirabe/src/repository/composer_repository.rs @@ -79,15 +79,6 @@ pub struct ProviderListingEntry { #[derive(Debug)] pub struct ComposerRepository { - // TODO(phase-c): PHP's ArrayRepository methods that aren't overridden here (findPackage, - // findPackages, count, hasPackage) call $this->getPackages(), which virtual-dispatches back - // to ComposerRepository::getPackages() (see its "embedded inheritance does not dispatch back - // to the wrapper" comment below, and the identical guard in load_packages()). Composition - // doesn't get that dispatch for free: self.inner.find_package()/find_packages()/count()/ - // has_package() below call ArrayRepository::initialize() (a no-op stub) instead, and will - // silently see an empty package list if called before get_packages()/load_packages() has - // run once on this instance. Not yet known to be hit by any test; audit call sites and add - // the same `if !self.inner.is_initialized() { self.initialize()?; }` guard where needed. inner: ArrayRepository, /// Weak reference to the outermost repository handle wrapping this `ComposerRepository`, /// injected via `set_self_handle`. Used to wire package -> repository back-references. @@ -3409,11 +3400,20 @@ fn clone_root_data(rd: &RootData) -> RootData { } impl RepositoryInterface for ComposerRepository { - fn count(&self) -> anyhow::Result<usize> { + // PHP's ArrayRepository::count()/hasPackage() call $this->initialize(), which + // virtual-dispatches to ComposerRepository::initialize(); the guard restores that + // (same guard as in get_packages()). + fn count(&mut self) -> anyhow::Result<usize> { + if !self.inner.is_initialized() { + self.initialize()?; + } self.inner.count() } - fn has_package(&self, package: PackageInterfaceHandle) -> bool { + fn has_package(&mut self, package: PackageInterfaceHandle) -> anyhow::Result<bool> { + if !self.inner.is_initialized() { + self.initialize()?; + } self.inner.has_package(package) } |
