Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
node: handle removal of cob from cache
Merged fintohaps opened 2 years ago

When a Patch or Issue is entirely removed from the Git repository, then there is no update to be made – instead it should also be removed from the cache.

This covers the case where the original author of the COB deletes the COB.

3 files changed +48 -7 53ecc884 8bf87190
modified radicle-cli/examples/rad-patch-delete.md
@@ -11,7 +11,7 @@ $ git commit -m "Introduce license"
``` ~alice (stderr)
$ git push rad -o patch.draft -o patch.message="Define LICENSE for project" HEAD:refs/patches
✓ Patch 6c61ef1716ad8a5c11e04dd7a3fec51e01fba70b drafted
-
✓ Synced with 1 node(s)
+
✓ Synced with 2 node(s)
To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
 * [new reference]   HEAD -> refs/patches
```
@@ -26,7 +26,7 @@ $ rad patch comment 6c61ef1 -m "I think we should use MIT"
│ bob (you) now 833db19     │
│ I think we should use MIT │
╰───────────────────────────╯
-
✓ Synced with 1 node(s)
+
✓ Synced with 2 node(s)
```

``` ~alice
@@ -53,7 +53,7 @@ $ rad patch comment 6c61ef1 --reply-to 833db19 -m "Thanks, I'll add it!"
│ alice (you) now 1803a38 │
│ Thanks, I'll add it!    │
╰─────────────────────────╯
-
✓ Synced with 1 node(s)
+
✓ Synced with 2 node(s)
```

``` ~alice
@@ -69,7 +69,7 @@ $ git commit -am "Add MIT License"
``` ~alice (stderr)
$ git push -f
✓ Patch 6c61ef1 updated to revision 93915b9afa94a9dc4f52f12cdf077d4613ea3eb3
-
✓ Synced with 1 node(s)
+
✓ Synced with 2 node(s)
To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
   717c900..1cc8cd9  prepare-license -> patches/6c61ef1716ad8a5c11e04dd7a3fec51e01fba70b
```
@@ -77,7 +77,7 @@ To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkE
``` ~bob
$ rad patch review 6c61ef1 --accept -m "LGTM!"
✓ Patch 6c61ef1 accepted
-
✓ Synced with 1 node(s)
+
✓ Synced with 2 node(s)
$ rad patch show 6c61ef1 -v
╭─────────────────────────────────────────────────────────────────────╮
│ Title    Define LICENSE for project                                 │
@@ -99,7 +99,7 @@ $ rad patch show 6c61ef1 -v

``` ~bob
$ rad patch delete 6c61ef1
-
✓ Synced with 1 node(s)
+
✓ Synced with 2 node(s)
```

``` ~alice
@@ -121,3 +121,16 @@ $ rad patch show 6c61ef1 -v
│ ↑ updated to 93915b9afa94a9dc4f52f12cdf077d4613ea3eb3 (1cc8cd9) now │
╰─────────────────────────────────────────────────────────────────────╯
```
+

+
If Alice also decides to delete the patch, then any seeds that have synced with
+
Alice should no longer have the patch:
+

+
``` ~alice
+
$ rad patch delete 6c61ef1
+
✓ Synced with 2 node(s)
+
```
+

+
``` ~seed (fails)
+
$ rad patch show --repo rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji 6c61ef1 -v
+
✗ Error: Patch `6c61ef1716ad8a5c11e04dd7a3fec51e01fba70b` not found
+
```
modified radicle-cli/tests/commands.rs
@@ -967,6 +967,7 @@ fn rad_patch_delete() {
    let mut environment = Environment::new();
    let alice = environment.node(Config::test(Alias::new("alice")));
    let bob = environment.node(Config::test(Alias::new("bob")));
+
    let seed = environment.node(Config::test(Alias::new("seed")));
    let working = environment.tmp().join("working");
    let acme = RepoId::from_str("z42hL2jL4XNk6K8oHQaSWfMgCL7ji").unwrap();

@@ -983,9 +984,11 @@ fn rad_patch_delete() {

    let mut alice = alice.spawn();
    let mut bob = bob.spawn();
+
    let mut seed = seed.spawn();

    bob.handle.seed(acme, Scope::All).unwrap();
-
    alice.connect(&bob).converge([&bob]);
+
    seed.handle.seed(acme, Scope::All).unwrap();
+
    alice.connect(&bob).connect(&seed).converge([&bob, &seed]);

    test(
        "examples/rad-clone.md",
@@ -1007,6 +1010,11 @@ fn rad_patch_delete() {
            working.join("bob"),
            [("RAD_HOME", bob.home.path().display())],
        )
+
        .home(
+
            "seed",
+
            working.join("seed"),
+
            [("RAD_HOME", seed.home.path().display())],
+
        )
        .run()
        .unwrap();
}
modified radicle-node/src/worker/fetch.rs
@@ -302,6 +302,16 @@ where
                                    type_name: identifier.type_name,
                                    err: e.into(),
                                })?;
+
                        } else {
+
                            // N.b. the issue has been removed entirely from the
+
                            // repository so we also remove it from the cache
+
                            cob::cache::Remove::<cob::issue::Issue>::remove(cache, &identifier.id)
+
                                .map(|_| ())
+
                                .map_err(|e| error::Cache::Remove {
+
                                    id: identifier.id,
+
                                    type_name: identifier.type_name,
+
                                    err: Box::new(e),
+
                                })?;
                        }
                    } else if identifier.is_patch() {
                        if let Some(patch) = patches.get(&identifier.id)? {
@@ -313,6 +323,16 @@ where
                                    type_name: identifier.type_name,
                                    err: e.into(),
                                })?;
+
                        } else {
+
                            // N.b. the patch has been removed entirely from the
+
                            // repository so we also remove it from the cache
+
                            cob::cache::Remove::<cob::patch::Patch>::remove(cache, &identifier.id)
+
                                .map(|_| ())
+
                                .map_err(|e| error::Cache::Remove {
+
                                    id: identifier.id,
+
                                    type_name: identifier.type_name,
+
                                    err: Box::new(e),
+
                                })?;
                        }
                    }
                }