Add `ReadStorage::contains` method
This commit is contained in:
parent
c673f5db68
commit
b461950d59
|
|
@ -254,6 +254,8 @@ pub trait ReadStorage {
|
||||||
remote: &RemoteId,
|
remote: &RemoteId,
|
||||||
rid: Id,
|
rid: Id,
|
||||||
) -> Result<Option<identity::Doc<Verified>>, ProjectError>;
|
) -> 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.
|
/// Get the inventory of repositories hosted under this storage.
|
||||||
fn inventory(&self) -> Result<Inventory, Error>;
|
fn inventory(&self) -> Result<Inventory, Error>;
|
||||||
}
|
}
|
||||||
|
|
@ -357,6 +359,10 @@ where
|
||||||
self.deref().path()
|
self.deref().path()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn contains(&self, rid: &Id) -> Result<bool, ProjectError> {
|
||||||
|
self.deref().contains(rid)
|
||||||
|
}
|
||||||
|
|
||||||
fn inventory(&self) -> Result<Inventory, Error> {
|
fn inventory(&self) -> Result<Inventory, Error> {
|
||||||
self.deref().inventory()
|
self.deref().inventory()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -99,6 +99,14 @@ impl ReadStorage for Storage {
|
||||||
self.path.as_path()
|
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> {
|
fn get(&self, remote: &RemoteId, proj: Id) -> Result<Option<Doc<Verified>>, ProjectError> {
|
||||||
// TODO: Don't create a repo here if it doesn't exist?
|
// TODO: Don't create a repo here if it doesn't exist?
|
||||||
// Perhaps for checking we could have a `contains` method?
|
// Perhaps for checking we could have a `contains` method?
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,10 @@ impl ReadStorage for MockStorage {
|
||||||
self.path.as_path()
|
self.path.as_path()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn contains(&self, rid: &Id) -> Result<bool, ProjectError> {
|
||||||
|
Ok(self.inventory.contains_key(rid))
|
||||||
|
}
|
||||||
|
|
||||||
fn get(
|
fn get(
|
||||||
&self,
|
&self,
|
||||||
_remote: &RemoteId,
|
_remote: &RemoteId,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue