cli: allow rad rm to untrack without running node
Previously, `rad rm` would require the node to be running to untrack the repository. This is no longer necessary since the tracking db is exposed via the `radicle` crate. Instead, use the db directly to untrack the RID during `rad rm`, as long as the node is not already running. Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com> X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
parent
6fe5dfa3c9
commit
c49412a73f
|
|
@ -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
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -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(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue