Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
Don't fail if we can't open the database
Alexis Sellier committed 2 years ago
commit b27313bc5c703c8a25343176c620c8652b815abc
parent eb701be033610992ed0a1a845e4ab9098dbd53bd
7 files changed +22 -25
modified radicle-cli/src/commands/checkout.rs
@@ -1,5 +1,4 @@
#![allow(clippy::box_default)]
-
use std::collections::HashMap;
use std::ffi::OsString;
use std::path::PathBuf;

@@ -140,11 +139,8 @@ pub fn setup_remotes(
    remotes: &[NodeId],
    profile: &Profile,
) -> anyhow::Result<()> {
-
    let aliases = if let Ok(aliases) = profile.aliases() {
-
        Box::new(aliases) as Box<dyn AliasStore>
-
    } else {
-
        Box::new(HashMap::new()) as Box<dyn AliasStore>
-
    };
+
    let aliases = profile.aliases();
+

    for remote_id in remotes {
        if let Err(e) = setup_remote(&setup, remote_id, None, &aliases) {
            term::warning(format!("Failed to setup remote for {remote_id}: {e}").as_str());
modified radicle-cli/src/commands/issue.rs
@@ -416,7 +416,7 @@ fn list(
    ]);
    table.divider();

-
    let aliases = profile.aliases()?;
+
    let aliases = profile.aliases();

    for (id, issue) in all {
        let assigned: String = issue
modified radicle-cli/src/commands/patch/list.rs
@@ -65,7 +65,7 @@ pub fn run(
        is_me.then(by_rev_time).then(by_id)
    });

-
    let aliases = profile.aliases()?;
+
    let aliases = profile.aliases();

    let mut errors = Vec::new();
    for (id, patch) in &mut all {
@@ -132,7 +132,7 @@ pub fn timeline(
    patch: &Patch,
    repository: &Repository,
) -> anyhow::Result<Vec<term::Line>> {
-
    let aliases = profile.aliases()?;
+
    let aliases = profile.aliases();
    let alias = aliases.alias(patch.author().id());
    let open = term::Line::spaced([
        term::format::positive("●").into(),
modified radicle-cli/src/commands/remote/add.rs
@@ -15,7 +15,7 @@ pub fn run(
    profile: &Profile,
    repo: &git::Repository,
) -> anyhow::Result<()> {
-
    let aliases = profile.aliases()?;
+
    let aliases = profile.aliases();
    let setup = SetupRemote {
        rid,
        tracking,
modified radicle-cli/src/terminal/format.rs
@@ -118,7 +118,7 @@ impl<'a> Identity<'a> {
impl<'a> fmt::Display for Identity<'a> {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let nid = self.profile.id();
-
        let alias = self.profile.aliases().ok().and_then(|a| a.alias(nid));
+
        let alias = self.profile.aliases().alias(nid);
        let node_id = match self.short {
            true => self::node(nid),
            false => nid.to_human(),
modified radicle-httpd/src/api/v1/projects.rs
@@ -324,7 +324,7 @@ async fn remotes_handler(State(ctx): State<Context>, Path(project): Path<Id>) ->
    let storage = &ctx.profile.storage;
    let repo = storage.repository(project)?;
    let delegates = repo.delegates()?;
-
    let aliases = &ctx.profile.aliases()?;
+
    let aliases = &ctx.profile.aliases();
    let remotes = repo
        .remotes()?
        .filter_map(|r| r.map(|r| r.1).ok())
@@ -454,7 +454,7 @@ async fn issues_handler(
        .collect::<Vec<_>>();

    issues.sort_by(|(_, a, _), (_, b, _)| b.timestamp().cmp(&a.timestamp()));
-
    let aliases = &ctx.profile.aliases()?;
+
    let aliases = &ctx.profile.aliases();
    let issues = issues
        .into_iter()
        .map(|(id, issue, _)| api::json::issue(id, issue, aliases))
@@ -568,7 +568,7 @@ async fn issue_handler(
    let issue = issue::Issues::open(&repo)?
        .get(&issue_id.into())?
        .ok_or(Error::NotFound)?;
-
    let aliases = ctx.profile.aliases()?;
+
    let aliases = ctx.profile.aliases();

    Ok::<_, Error>(Json(api::json::issue(issue_id.into(), issue, &aliases)))
}
@@ -732,7 +732,7 @@ async fn patches_handler(
        })
        .collect::<Vec<_>>();
    patches.sort_by(|(_, a, _), (_, b, _)| b.timestamp().cmp(&a.timestamp()));
-
    let aliases = ctx.profile.aliases()?;
+
    let aliases = ctx.profile.aliases();
    let patches = patches
        .into_iter()
        .map(|(id, patch, _)| api::json::patch(id, patch, &repo, &aliases))
@@ -754,7 +754,7 @@ async fn patch_handler(
    let patch = patch::Patches::open(&repo)?
        .get(&patch_id.into())?
        .ok_or(Error::NotFound)?;
-
    let aliases = ctx.profile.aliases()?;
+
    let aliases = ctx.profile.aliases();

    Ok::<_, Error>(Json(api::json::patch(
        patch_id.into(),
modified radicle/src/profile.rs
@@ -232,14 +232,14 @@ impl Profile {
    }

    /// Return a multi-source store for aliases.
-
    pub fn aliases(&self) -> Result<Aliases, Error> {
-
        let tracking = self.tracking()?;
-
        let addresses = self.addresses()?;
+
    pub fn aliases(&self) -> Aliases {
+
        let tracking = self.tracking().ok();
+
        let addresses = self.addresses().ok();

-
        Ok(Aliases {
+
        Aliases {
            tracking,
            addresses,
-
        })
+
        }
    }

    /// Return the path to the keys folder.
@@ -261,8 +261,8 @@ impl Profile {
/// Holds multiple alias stores, and will try
/// them one by one when asking for an alias.
pub struct Aliases {
-
    tracking: tracking::store::Config,
-
    addresses: address::Book,
+
    tracking: Option<tracking::store::Config>,
+
    addresses: Option<address::Book>,
}

impl AliasStore for Aliases {
@@ -270,8 +270,9 @@ impl AliasStore for Aliases {
    /// First looks in `tracking.db` and then `addresses.db`.
    fn alias(&self, nid: &NodeId) -> Option<Alias> {
        self.tracking
-
            .alias(nid)
-
            .or_else(|| self.addresses.alias(nid))
+
            .as_ref()
+
            .and_then(|db| db.alias(nid))
+
            .or_else(|| self.addresses.as_ref().and_then(|db| db.alias(nid)))
    }
}