From 97b5211ab3a41d63ea50d0ca1ecfde6ad3323525 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 2 Aug 2026 17:43:26 +0900 Subject: fix(repository): restore late-bound initialize in FilesystemRepository add/remove ArrayRepository::addPackage()/removePackage() rely on PHP late binding to run FilesystemRepository::initialize (reading the file) on first touch. The inner delegation skipped that: an add on a not-yet-read repository froze the array to just the added packages (a later write() would truncate installed.json), and a remove hit the packages-initialized expect(). Guard both with ensure_initialized(), matching the pattern used by the read paths. Same defect class as the 3e367f78 downloader fix. Co-Authored-By: Claude Fable 5 --- crates/shirabe/src/repository/filesystem_repository.rs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'crates/shirabe/src/repository/filesystem_repository.rs') diff --git a/crates/shirabe/src/repository/filesystem_repository.rs b/crates/shirabe/src/repository/filesystem_repository.rs index 9186a836..88317be2 100644 --- a/crates/shirabe/src/repository/filesystem_repository.rs +++ b/crates/shirabe/src/repository/filesystem_repository.rs @@ -179,10 +179,18 @@ impl FilesystemRepository { } pub fn add_package(&mut self, package: PackageInterfaceHandle) -> anyhow::Result<()> { + // PHP: ArrayRepository::addPackage() calls the late-bound $this->initialize(), which must + // resolve to FilesystemRepository::initialize (reading the file). Without this guard the + // inner ArrayRepository would self-initialize to an empty array and the file would never + // be read (and a later write() would truncate it to just the added packages). + self.ensure_initialized()?; self.inner.add_package(package) } pub fn remove_package(&mut self, package: PackageInterfaceHandle) -> anyhow::Result<()> { + // PHP: ArrayRepository::removePackage() iterates the late-bound $this->getPackages(), + // which initializes through FilesystemRepository::initialize first. + self.ensure_initialized()?; self.inner.remove_package(package) } -- cgit v1.3.1