Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli: allow rad rm to untrack without running node
Fintan Halpenny committed 3 years ago
commit c49412a73fef2233473f9ffe5fd62b12301c52f4
parent 6fe5dfa3c95f2532f9327e1d0bde7e4f12f57a75
2 files changed +26 -8
modified radicle-cli/examples/rad-rm.md
@@ -10,8 +10,7 @@ Now let's delete the `heartwood` project:

```
$ rad rm rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji --no-confirm
-
! Warning: Failed to untrack repository: failed to connect to node: No such file or directory (os error 2)
-
! Warning: Make sure to untrack this repository when your node is running
+
✓ Untracked rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji
✓ Successfully removed rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji from storage
```

modified radicle-cli/src/commands/rm.rs
@@ -4,8 +4,10 @@ use std::fs;
use anyhow::anyhow;

use radicle::identity::Id;
+
use radicle::node;
+
use radicle::node::Handle as _;
+
use radicle::Profile;

-
use crate::commands::rad_untrack;
use crate::terminal as term;
use crate::terminal::args::{Args, Error, Help};

@@ -70,20 +72,37 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
    let storage = &profile.storage;
    let rid = options.rid;
    let path = radicle::storage::git::paths::repository(storage, &rid);
-
    let mut node = radicle::Node::new(profile.socket());

    if !path.exists() {
        anyhow::bail!("repository {rid} was not found");
    }

    if !options.confirm || term::confirm(format!("Remove {rid}?")) {
-
        if let Err(e) = rad_untrack::untrack_repo(rid, &mut node) {
-
            term::warning(&format!("Failed to untrack repository: {e}"));
-
            term::warning("Make sure to untrack this repository when your node is running");
-
        }
+
        untrack(&rid, &profile)?;
        fs::remove_dir_all(path)?;
        term::success!("Successfully removed {rid} from storage");
    }

    Ok(())
}
+

+
fn untrack(rid: &Id, profile: &Profile) -> anyhow::Result<()> {
+
    let mut node = radicle::Node::new(profile.socket());
+

+
    let result = if node.is_running() {
+
        node.untrack_repo(*rid).map_err(anyhow::Error::from)
+
    } else {
+
        let mut store =
+
            node::tracking::store::Config::open(profile.home.node().join(node::TRACKING_DB_FILE))?;
+
        store.untrack_repo(rid).map_err(anyhow::Error::from)
+
    };
+

+
    if let Err(e) = result {
+
        term::warning(&format!("Failed to untrack repository: {e}"));
+
        term::warning("Make sure to untrack this repository when your node is running");
+
    } else {
+
        term::success!("Untracked {rid}")
+
    }
+

+
    Ok(())
+
}