Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
Add `ReadStorage::contains` method
Alexis Sellier committed 3 years ago
commit b461950d59f55fccb8cf4bfed1d7c99fb9444018
parent c673f5db6818bc93d33674ebe833645f944133bd
3 files changed +18 -0
modified radicle/src/storage.rs
@@ -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()
    }
modified radicle/src/storage/git.rs
@@ -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?
modified radicle/src/test/storage.rs
@@ -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,