mirror of
https://seed.radicle.dev/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5.git
synced 2026-11-21 18:40:39 +08:00
Make ReadStorage more usable
Previously, we were not able to access a `ReadRepository` instance through `ReadStorage`. With this change, we are able to.
This commit is contained in:
@@ -10,7 +10,7 @@ use crate::service::filter::Filter;
|
||||
use crate::service::{NodeId, Timestamp};
|
||||
use crate::storage;
|
||||
use crate::storage::refs::SignedRefs;
|
||||
use crate::storage::{ReadRepository, WriteStorage};
|
||||
use crate::storage::{ReadRepository, ReadStorage};
|
||||
use crate::wire;
|
||||
|
||||
/// Maximum number of addresses which can be announced to other nodes.
|
||||
@@ -154,8 +154,14 @@ pub struct RefsAnnouncement {
|
||||
|
||||
impl RefsAnnouncement {
|
||||
/// Check if this announcement is "fresh", meaning if it contains refs we do not have.
|
||||
pub fn is_fresh<S: WriteStorage>(&self, storage: S) -> Result<bool, storage::Error> {
|
||||
let repo = storage.repository(self.rid)?;
|
||||
pub fn is_fresh<S: ReadStorage>(&self, storage: S) -> Result<bool, storage::Error> {
|
||||
let repo = match storage.repository(self.rid) {
|
||||
// If the repo doesn't exist, we consider this announcement "fresh", since we
|
||||
// obviously don't have the refs.
|
||||
Err(e) if e.is_not_found() => return Ok(true),
|
||||
Err(e) => return Err(e),
|
||||
Ok(r) => r,
|
||||
};
|
||||
|
||||
for (remote_id, theirs) in self.refs.iter() {
|
||||
if let Ok(ours) = repo.remote(remote_id) {
|
||||
|
||||
@@ -411,7 +411,11 @@ impl<S: WriteStorage + 'static, G: Signer> Simulation<S, G> {
|
||||
Input::Fetched(f, result) => {
|
||||
let result = Rc::try_unwrap(result).unwrap();
|
||||
if f.initiated {
|
||||
let mut repo = p.storage().repository(f.rid).unwrap();
|
||||
let mut repo = match p.storage().repository_mut(f.rid) {
|
||||
Ok(repo) => repo,
|
||||
Err(e) if e.is_not_found() => p.storage().create(f.rid).unwrap(),
|
||||
Err(e) => panic!("Failed to open repository: {e}"),
|
||||
};
|
||||
fetch(&mut repo, &f.remote, f.namespaces.clone()).unwrap();
|
||||
}
|
||||
p.fetched(f, result);
|
||||
|
||||
@@ -2,7 +2,7 @@ use std::{thread, time};
|
||||
|
||||
use radicle::crypto::Signer;
|
||||
use radicle::node::{FetchResult, Handle as _};
|
||||
use radicle::storage::{ReadRepository, WriteStorage};
|
||||
use radicle::storage::{ReadRepository, ReadStorage};
|
||||
use radicle::{assert_matches, rad};
|
||||
|
||||
use crate::service;
|
||||
|
||||
@@ -166,7 +166,11 @@ impl<G: Signer + Ecdh + 'static> Worker<G> {
|
||||
fetch: &Fetch,
|
||||
tunnel: &mut Tunnel<WireSession<G>>,
|
||||
) -> Result<Vec<RefUpdate>, FetchError> {
|
||||
let repo = self.storage.repository(fetch.rid)?;
|
||||
let repo = match self.storage.repository_mut(fetch.rid) {
|
||||
Ok(r) => Ok(r),
|
||||
Err(e) if e.is_not_found() => self.storage.create(fetch.rid),
|
||||
Err(e) => Err(e),
|
||||
}?;
|
||||
let tunnel_addr = tunnel.local_addr()?;
|
||||
let mut cmd = process::Command::new("git");
|
||||
cmd.current_dir(repo.path())
|
||||
|
||||
Reference in New Issue
Block a user