Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
node: Make `Storage::refresh` private
cloudhead committed 2 years ago
commit d771ce85224c9abd4fb731f1667259751537ac34
parent 2bcb03b021af544142532e97441d2c9efcf4a688
6 files changed +26 -39
modified radicle-node/src/tests/e2e.rs
@@ -160,7 +160,7 @@ fn test_replication() {
    alice.connect(&bob);
    converge([&alice, &bob]);

-
    let inventory = alice.storage.inventory().unwrap();
+
    let inventory = alice.storage.repositories().unwrap();
    assert!(inventory.is_empty());

    let updated = alice.handle.seed(acme, Scope::All).unwrap();
@@ -182,10 +182,7 @@ fn test_replication() {

    log::debug!(target: "test", "Fetch complete with {}", bob.id);

-
    alice.storage.refresh().unwrap();
-
    bob.storage.refresh().unwrap();
-

-
    let inventory = alice.storage.inventory().unwrap();
+
    let inventory = alice.storage.repositories().unwrap();
    let alice_repo = alice.storage.repository(acme).unwrap();
    let bob_repo = bob.storage.repository(acme).unwrap();

@@ -200,7 +197,7 @@ fn test_replication() {
        .collect::<Result<Vec<_>, _>>()
        .unwrap();

-
    assert_eq!(inventory.first(), Some(&acme));
+
    assert_eq!(inventory.first().map(|r| r.rid), Some(acme));
    assert_eq!(alice_refs, bob_refs);
    assert_matches!(
        alice.storage.repository(acme).unwrap().validate(),
modified radicle/src/rad.rs
@@ -73,6 +73,9 @@ pub fn init<G: Signer, S: WriteStorage>(
    let (project, _) = Repository::init(&doc, &storage, signer)?;
    let url = git::Url::from(project.id);

+
    // Update inventory cache for this storage instance.
+
    storage.insert(project.id);
+

    match init_configure(repo, &project, pk, &default_branch, &url, signer) {
        Ok(signed) => Ok((project.id, doc, signed)),
        Err(err) => {
modified radicle/src/storage.rs
@@ -376,8 +376,6 @@ pub trait ReadStorage {
    fn inventory(&self) -> Result<Inventory, Error>;
    /// Insert this repository into the inventory.
    fn insert(&self, rid: RepoId);
-
    /// Refresh storage inventory.
-
    fn refresh(&self) -> Result<(), Error>;
    /// Open or create a read-only repository.
    fn repository(&self, rid: RepoId) -> Result<Self::Repository, Error>;
    /// Get a repository's identity if it exists.
@@ -640,10 +638,6 @@ where
        self.deref().inventory()
    }

-
    fn refresh(&self) -> Result<(), Error> {
-
        self.deref().refresh()
-
    }
-

    fn get(&self, rid: RepoId) -> Result<Option<Doc<Verified>>, RepositoryError> {
        self.deref().get(rid)
    }
modified radicle/src/storage/git.rs
@@ -137,26 +137,6 @@ impl ReadStorage for Storage {
        }
    }

-
    fn refresh(&self) -> Result<(), Error> {
-
        let repos = self.repositories()?;
-
        let rids = repos
-
            .into_iter()
-
            .filter(|r| r.doc.visibility.is_public())
-
            .map(|r| r.rid)
-
            .collect();
-

-
        match self.inventory.lock() {
-
            Ok(mut locked) => {
-
                *locked = rids;
-
            }
-
            Err(poisoned) => {
-
                let mut inv = poisoned.into_inner();
-
                *inv = rids;
-
            }
-
        }
-
        Ok(())
-
    }
-

    fn repository(&self, rid: RepoId) -> Result<Self::Repository, Error> {
        Repository::open(paths::repository(self, &rid), rid)
    }
@@ -325,6 +305,26 @@ impl Storage {
        }
        Ok(())
    }
+

+
    fn refresh(&self) -> Result<(), Error> {
+
        let repos = self.repositories()?;
+
        let rids = repos
+
            .into_iter()
+
            .filter(|r| r.doc.visibility.is_public())
+
            .map(|r| r.rid)
+
            .collect();
+

+
        match self.inventory.lock() {
+
            Ok(mut locked) => {
+
                *locked = rids;
+
            }
+
            Err(poisoned) => {
+
                let mut inv = poisoned.into_inner();
+
                *inv = rids;
+
            }
+
        }
+
        Ok(())
+
    }
}

/// Git implementation of [`WriteRepository`] using the `git2` crate.
modified radicle/src/test/fixtures.rs
@@ -10,7 +10,6 @@ use crate::rad;
use crate::storage::git::transport;
use crate::storage::git::Storage;
use crate::storage::refs::SignedRefs;
-
use crate::storage::ReadStorage;

/// The birth of the radicle project, January 1st, 2018.
pub const RADICLE_EPOCH: i64 = 1514817556;
@@ -47,7 +46,6 @@ pub fn storage<P: AsRef<Path>, G: Signer>(path: P, signer: &G) -> Result<Storage
            &storage,
        )?;
    }
-
    storage.refresh()?;

    Ok(storage)
}
@@ -70,7 +68,6 @@ pub fn project<P: AsRef<Path>, G: Signer>(
        signer,
        storage,
    )?;
-
    storage.refresh()?;

    Ok((id, refs, working, head))
}
modified radicle/src/test/storage.rs
@@ -81,10 +81,6 @@ impl ReadStorage for MockStorage {

    fn insert(&self, _rid: RepoId) {}

-
    fn refresh(&self) -> Result<(), Error> {
-
        Ok(())
-
    }
-

    fn repository(&self, rid: RepoId) -> Result<Self::Repository, Error> {
        self.repos
            .get(&rid)