diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-06 02:13:59 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-06 02:13:59 +0900 |
| commit | cd25c3e193f05a5e89bca2a1c706c85fdc9c9155 (patch) | |
| tree | 86971cac4e5011af0077416e6ca674c4251496ee /crates/shirabe/src/repository/handle.rs | |
| parent | b299a0c9b66523b9630b4cf6d3dca1509c3692b5 (diff) | |
| download | php-shirabe-cd25c3e193f05a5e89bca2a1c706c85fdc9c9155.tar.gz php-shirabe-cd25c3e193f05a5e89bca2a1c706c85fdc9c9155.tar.zst php-shirabe-cd25c3e193f05a5e89bca2a1c706c85fdc9c9155.zip | |
refactor(repository): make read methods fallible and take &mut self
Change RepositoryInterface and WritableRepositoryInterface read methods
(find_package, find_packages, get_packages, load_packages, search,
get_providers, get_canonical_packages) to take &mut self and return
anyhow::Result, so lazy-loading repositories such as ComposerRepository
can perform fallible I/O and mutate internal state on access. Update all
implementors and call sites to propagate the Result and pass mutable
references.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/repository/handle.rs')
| -rw-r--r-- | crates/shirabe/src/repository/handle.rs | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/crates/shirabe/src/repository/handle.rs b/crates/shirabe/src/repository/handle.rs index 73d4493..0d02b83 100644 --- a/crates/shirabe/src/repository/handle.rs +++ b/crates/shirabe/src/repository/handle.rs @@ -74,8 +74,8 @@ impl RepositoryInterfaceHandle { self.0.borrow().get_repo_name() } - pub fn get_packages(&self) -> Vec<BasePackageHandle> { - self.0.borrow().get_packages() + pub fn get_packages(&self) -> anyhow::Result<Vec<BasePackageHandle>> { + self.0.borrow_mut().get_packages() } pub fn has_package(&self, package: PackageInterfaceHandle) -> bool { @@ -86,16 +86,16 @@ impl RepositoryInterfaceHandle { &self, name: &str, constraint: FindPackageConstraint, - ) -> Option<BasePackageHandle> { - self.0.borrow().find_package(name, constraint) + ) -> anyhow::Result<Option<BasePackageHandle>> { + self.0.borrow_mut().find_package(name, constraint) } pub fn find_packages( &self, name: &str, constraint: Option<FindPackageConstraint>, - ) -> Vec<BasePackageHandle> { - self.0.borrow().find_packages(name, constraint) + ) -> anyhow::Result<Vec<BasePackageHandle>> { + self.0.borrow_mut().find_packages(name, constraint) } pub fn load_packages( @@ -104,8 +104,8 @@ impl RepositoryInterfaceHandle { acceptable_stabilities: IndexMap<String, i64>, stability_flags: IndexMap<String, i64>, already_loaded: IndexMap<String, IndexMap<String, PackageInterfaceHandle>>, - ) -> LoadPackagesResult { - self.0.borrow().load_packages( + ) -> anyhow::Result<LoadPackagesResult> { + self.0.borrow_mut().load_packages( package_name_map, acceptable_stabilities, stability_flags, @@ -113,12 +113,20 @@ impl RepositoryInterfaceHandle { ) } - pub fn search(&self, query: String, mode: i64, r#type: Option<String>) -> Vec<SearchResult> { - self.0.borrow().search(query, mode, r#type) + pub fn search( + &self, + query: String, + mode: i64, + r#type: Option<String>, + ) -> anyhow::Result<Vec<SearchResult>> { + self.0.borrow_mut().search(query, mode, r#type) } - pub fn get_providers(&self, package_name: String) -> IndexMap<String, ProviderInfo> { - self.0.borrow().get_providers(package_name) + pub fn get_providers( + &self, + package_name: String, + ) -> anyhow::Result<IndexMap<String, ProviderInfo>> { + self.0.borrow_mut().get_providers(package_name) } // --- InstalledRepositoryInterface helpers (valid only when the wrapped repository is one) --- @@ -137,12 +145,11 @@ impl RepositoryInterfaceHandle { .and_then(|r| r.get_dev_mode()) } - pub fn get_canonical_packages(&self) -> Vec<PackageInterfaceHandle> { - self.0 - .borrow() - .as_installed_repository_interface() - .map(|r| r.get_canonical_packages()) - .unwrap_or_default() + pub fn get_canonical_packages(&self) -> anyhow::Result<Vec<PackageInterfaceHandle>> { + match self.0.borrow_mut().as_installed_repository_interface_mut() { + Some(r) => r.get_canonical_packages(), + None => Ok(Vec::new()), + } } pub fn get_dev_package_names(&self) -> Vec<String> { |
