mirror of
https://seed.radicle.dev/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5.git
synced 2026-11-29 14:00:31 +08:00
Add ReadStorage::contains method
This commit is contained in:
@@ -254,6 +254,8 @@ pub trait ReadStorage {
|
||||
remote: &RemoteId,
|
||||
rid: Id,
|
||||
) -> Result<Option<identity::Doc<Verified>>, ProjectError>;
|
||||
/// Check whether storage contains a repository.
|
||||
fn contains(&self, rid: &Id) -> Result<bool, ProjectError>;
|
||||
/// Get the inventory of repositories hosted under this storage.
|
||||
fn inventory(&self) -> Result<Inventory, Error>;
|
||||
}
|
||||
@@ -357,6 +359,10 @@ where
|
||||
self.deref().path()
|
||||
}
|
||||
|
||||
fn contains(&self, rid: &Id) -> Result<bool, ProjectError> {
|
||||
self.deref().contains(rid)
|
||||
}
|
||||
|
||||
fn inventory(&self) -> Result<Inventory, Error> {
|
||||
self.deref().inventory()
|
||||
}
|
||||
|
||||
@@ -99,6 +99,14 @@ impl ReadStorage for Storage {
|
||||
self.path.as_path()
|
||||
}
|
||||
|
||||
fn contains(&self, rid: &Id) -> Result<bool, ProjectError> {
|
||||
if paths::repository(&self, rid).exists() {
|
||||
let _ = self.repository(*rid)?.head()?;
|
||||
return Ok(true);
|
||||
}
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
fn get(&self, remote: &RemoteId, proj: Id) -> Result<Option<Doc<Verified>>, ProjectError> {
|
||||
// TODO: Don't create a repo here if it doesn't exist?
|
||||
// Perhaps for checking we could have a `contains` method?
|
||||
|
||||
@@ -36,6 +36,10 @@ impl ReadStorage for MockStorage {
|
||||
self.path.as_path()
|
||||
}
|
||||
|
||||
fn contains(&self, rid: &Id) -> Result<bool, ProjectError> {
|
||||
Ok(self.inventory.contains_key(rid))
|
||||
}
|
||||
|
||||
fn get(
|
||||
&self,
|
||||
_remote: &RemoteId,
|
||||
|
||||
Reference in New Issue
Block a user