Add Store::exists() for checking whether a StoreId exists as Entry
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
parent
ccd8e94fbf
commit
4fe7fd366c
1 changed files with 17 additions and 15 deletions
|
@ -222,13 +222,7 @@ impl Store {
|
||||||
|
|
||||||
debug!("Creating id: '{}'", id);
|
debug!("Creating id: '{}'", id);
|
||||||
|
|
||||||
let exists =
|
let exists = self.exists(id.clone())?;
|
||||||
self.entries
|
|
||||||
.read()
|
|
||||||
.map(|map| map.contains_key(&id))
|
|
||||||
.map_err(|_| Error::from(EM::LockError))
|
|
||||||
.context(format_err!("CreateCallError: {}", id))? ||
|
|
||||||
self.backend.exists(&id.clone().into_pathbuf()?)?;
|
|
||||||
|
|
||||||
if exists {
|
if exists {
|
||||||
debug!("Entry exists: {:?}", id);
|
debug!("Entry exists: {:?}", id);
|
||||||
|
@ -306,14 +300,7 @@ impl Store {
|
||||||
|
|
||||||
debug!("Getting id: '{}'", id);
|
debug!("Getting id: '{}'", id);
|
||||||
|
|
||||||
let exists =
|
let exists = self.exists(id.clone())?;
|
||||||
self.entries
|
|
||||||
.read()
|
|
||||||
.map(|map| map.contains_key(&id))
|
|
||||||
.map_err(|_| Error::from(EM::LockError))
|
|
||||||
.context(format_err!("CreateCallError: {}", id))? ||
|
|
||||||
self.backend.exists(&id.clone().into_pathbuf()?)?;
|
|
||||||
|
|
||||||
|
|
||||||
if !exists {
|
if !exists {
|
||||||
debug!("Does not exist in internal cache or filesystem: {:?}", id);
|
debug!("Does not exist in internal cache or filesystem: {:?}", id);
|
||||||
|
@ -648,6 +635,21 @@ impl Store {
|
||||||
.map(|i| Entries::new(i, self))
|
.map(|i| Entries::new(i, self))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Check whether the store has the Entry pointed to by the StoreId `id`
|
||||||
|
pub fn exists<'a>(&'a self, id: StoreId) -> Result<bool> {
|
||||||
|
let cache_has_entry = |id: &StoreId|
|
||||||
|
self.entries
|
||||||
|
.read()
|
||||||
|
.map(|map| map.contains_key(id))
|
||||||
|
.map_err(|_| Error::from(EM::LockError))
|
||||||
|
.context(format_err!("CreateCallError: {}", id));
|
||||||
|
|
||||||
|
let backend_has_entry = |id: StoreId|
|
||||||
|
self.backend.exists(&id.with_base(self.path().to_path_buf()).into_pathbuf()?);
|
||||||
|
|
||||||
|
Ok(cache_has_entry(&id)? || backend_has_entry(id)?)
|
||||||
|
}
|
||||||
|
|
||||||
/// Gets the path where this store is on the disk
|
/// Gets the path where this store is on the disk
|
||||||
pub fn path(&self) -> &PathBuf {
|
pub fn path(&self) -> &PathBuf {
|
||||||
&self.location
|
&self.location
|
||||||
|
|
Loading…
Reference in a new issue