mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-29 02:00:31 +08:00
Fix unseed error paths and seeded repo filter
Unseeding only deletes the policy row, so a node defaulting to `allow` keeps seeding: `unseed` now reports `DefaultPolicySeeds` instead of claiming success, and both callers refresh in a `finally` so a failed `clean` no longer leaves a stale row behind.
This commit is contained in:
@@ -19,8 +19,9 @@ pub async fn list_repos(
|
||||
#[tauri::command]
|
||||
pub async fn list_repos_summary(
|
||||
ctx: tauri::State<'_, AppState>,
|
||||
show: Show,
|
||||
) -> Result<Vec<types::repo::RepoSummary>, Error> {
|
||||
blocking(ctx, |ctx| ctx.list_repos_summary()).await
|
||||
blocking(ctx, move |ctx| ctx.list_repos_summary(show)).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
|
||||
@@ -39,6 +39,13 @@ pub enum Error {
|
||||
#[error("you have already reviewed this revision")]
|
||||
ReviewExists,
|
||||
|
||||
/// Unseeding had no effect because the node seeds everything by default.
|
||||
#[error(
|
||||
"this node's default seeding policy is 'allow', so it keeps seeding this repository; \
|
||||
change `node.seedingPolicy` in your Radicle config to stop"
|
||||
)]
|
||||
DefaultPolicySeeds,
|
||||
|
||||
/// Init Error error.
|
||||
#[error(transparent)]
|
||||
InitError(#[from] radicle::rad::InitError),
|
||||
|
||||
@@ -386,7 +386,7 @@ pub trait Repo: Profile {
|
||||
Ok::<_, Error>(entries)
|
||||
}
|
||||
|
||||
fn list_repos_summary(&self) -> Result<Vec<repo::RepoSummary>, Error> {
|
||||
fn list_repos_summary(&self, show: Show) -> Result<Vec<repo::RepoSummary>, Error> {
|
||||
let profile = self.profile();
|
||||
let storage = &profile.storage;
|
||||
let policies = profile.policies()?;
|
||||
@@ -394,11 +394,7 @@ pub trait Repo: Profile {
|
||||
let mut entries = Vec::new();
|
||||
|
||||
for RepositoryInfo { rid, doc, .. } in repos {
|
||||
// `rad unseed` only drops the seeding policy; the repository stays
|
||||
// in storage. This list backs the sidebar, which is about what you
|
||||
// seed, so an unseeded repo has to leave it even though its files
|
||||
// are still on disk — otherwise unseeding looks like it did nothing.
|
||||
if !policies.is_seeding(&rid)? {
|
||||
if !policies.is_seeding(&rid)? && show == Show::Seeded {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -927,6 +923,13 @@ pub trait Repo: Profile {
|
||||
|
||||
profile.unseed(rid, &mut node)?;
|
||||
|
||||
// Unseeding deletes the repository's policy row, so a node whose
|
||||
// default seeding policy is `allow` carries on seeding it. Saying so is
|
||||
// better than reporting success and leaving the repo where it was.
|
||||
if profile.policies()?.is_seeding(&rid)? {
|
||||
return Err(Error::DefaultPolicySeeds);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -165,8 +165,11 @@ async fn repo_count_handler(State(ctx): State<Context>) -> impl IntoResponse {
|
||||
Ok::<_, Error>(Json(repos))
|
||||
}
|
||||
|
||||
async fn list_repos_summary_handler(State(ctx): State<Context>) -> impl IntoResponse {
|
||||
let repos = ctx.list_repos_summary()?;
|
||||
async fn list_repos_summary_handler(
|
||||
State(ctx): State<Context>,
|
||||
Json(Options { show }): Json<Options>,
|
||||
) -> impl IntoResponse {
|
||||
let repos = ctx.list_repos_summary(show)?;
|
||||
Ok::<_, Error>(Json(repos))
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
import type { Config } from "@bindings/config/Config";
|
||||
import type { RepoInfo } from "@bindings/repo/RepoInfo";
|
||||
import type { RepoSummary } from "@bindings/repo/RepoSummary";
|
||||
import type { CrossfadeParams } from "svelte/transition";
|
||||
|
||||
import { onMount } from "svelte";
|
||||
import { flip } from "svelte/animate";
|
||||
@@ -209,13 +210,21 @@
|
||||
duration: ANIMATION_DURATION_MS,
|
||||
// A row leaving with no counterpart is either the repo being unseeded, or a
|
||||
// filter/refresh that should not animate at all.
|
||||
fallback: (node, params) =>
|
||||
(params as { key?: string }).key !== undefined &&
|
||||
(params as { key?: string }).key === unseedingRid
|
||||
fallback: (node: Element, params: CrossfadeParams & { key?: string }) =>
|
||||
params.key !== undefined && params.key === unseedingRid
|
||||
? fadeCollapse(node, ANIMATION_DURATION_MS)
|
||||
: { duration: 0 },
|
||||
});
|
||||
|
||||
// Normally cleared when the row finishes its outro; the timer is only a
|
||||
// backstop for a row that leaves without ever running one, which would
|
||||
// otherwise leave every later list change animating.
|
||||
function clearUnseeding(rid: string) {
|
||||
if (unseedingRid === rid) {
|
||||
unseedingRid = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
// Fades the row out while collapsing the space it occupies, so the rows below
|
||||
// rise into the gap as it closes. `animate:flip` cannot do this on its own: a
|
||||
// row mid-out-transition still takes up its full height, so flip measures no
|
||||
@@ -271,20 +280,34 @@
|
||||
]);
|
||||
}
|
||||
|
||||
// Ordered like the CLI: drop the seeding policy first, then let storage prune
|
||||
// what it can. `clean` keeps the local node's and the delegates' refs, so a
|
||||
// repo we have published to survives in a reduced form. Throws, so each
|
||||
// caller decides how loud a failure is.
|
||||
async function stopSeeding(rid: string, clean = false) {
|
||||
await invoke<null>("unseed", { rid });
|
||||
if (clean) {
|
||||
await invoke<null>("clean", { rid });
|
||||
}
|
||||
}
|
||||
|
||||
// The pending-fetch list's trash button, which stays quiet on failure. The
|
||||
// list still refreshes: dropping the policy row is what removes a repo from
|
||||
// it, and that happens before anything can throw.
|
||||
async function unseed(rid: string) {
|
||||
try {
|
||||
await invoke<null>("unseed", { rid });
|
||||
await reloadRepos();
|
||||
await stopSeeding(rid);
|
||||
} catch (error) {
|
||||
console.error("Unseed failed", error);
|
||||
} finally {
|
||||
await reloadRepos().catch(error =>
|
||||
console.error("Reloading repos failed", error),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Unseeding drops the seeding policy and removes the repo from this list, so
|
||||
// it goes through a confirmation rather than firing straight off a menu item.
|
||||
// It does not reuse `unseed` above, which swallows its error to keep the
|
||||
// pending-fetch list's trash button quiet — here the error has to reach the
|
||||
// dialog.
|
||||
function confirmUnseed(repo: RepoSummary) {
|
||||
show({
|
||||
component: ConfirmUnseed,
|
||||
@@ -292,29 +315,30 @@
|
||||
name: repo.name,
|
||||
rid: repo.rid,
|
||||
async confirm(clean: boolean) {
|
||||
await invoke<null>("unseed", { rid: repo.rid });
|
||||
// Ordered like the CLI: drop the seeding policy first, then let
|
||||
// storage prune what it can. `clean` keeps the local node's and the
|
||||
// delegates' refs, so a repo we have published to survives in a
|
||||
// reduced form.
|
||||
if (clean) {
|
||||
await invoke<null>("clean", { rid: repo.rid });
|
||||
}
|
||||
// Marked before the list refreshes so the row that disappears fades
|
||||
// out instead of blinking away, and the rows below glide up into the
|
||||
// gap. Cleared once both halves have run.
|
||||
// Marked before the commands run so the row that disappears fades out
|
||||
// instead of blinking away, and the rows below glide up into the gap.
|
||||
unseedingRid = repo.rid;
|
||||
try {
|
||||
await reloadRepos();
|
||||
await stopSeeding(repo.rid, clean);
|
||||
} finally {
|
||||
setTimeout(() => {
|
||||
unseedingRid = undefined;
|
||||
}, ANIMATION_DURATION_MS * 2);
|
||||
}
|
||||
// The repo the user is looking at just went away; its route would
|
||||
// resolve to nothing.
|
||||
if (activeRid() === repo.rid) {
|
||||
await router.push({ resource: "inbox" });
|
||||
// `unseed` goes first, so it may well have succeeded even when
|
||||
// `clean` threw. Refresh either way rather than leave a row behind
|
||||
// for a repo that is no longer seeded.
|
||||
await reloadRepos().catch(error =>
|
||||
console.error("Reloading repos failed", error),
|
||||
);
|
||||
setTimeout(
|
||||
() => clearUnseeding(repo.rid),
|
||||
ANIMATION_DURATION_MS * 2,
|
||||
);
|
||||
// The repo the user is looking at may have just gone away; its
|
||||
// route would resolve to nothing.
|
||||
if (
|
||||
activeRid() === repo.rid &&
|
||||
!repos.some(r => r.rid === repo.rid)
|
||||
) {
|
||||
await router.push({ resource: "inbox" });
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
@@ -714,7 +738,8 @@
|
||||
{...{ [DRAG_RID_ATTRIBUTE]: repo.rid }}
|
||||
animate:flip={{ duration: animationDuration }}
|
||||
in:receive={{ key: repo.rid, duration: animationDuration }}
|
||||
out:send={{ key: repo.rid, duration: animationDuration }}>
|
||||
out:send={{ key: repo.rid, duration: animationDuration }}
|
||||
onoutroend={() => clearUnseeding(repo.rid)}>
|
||||
{@render repoRowInner(repo, true)}
|
||||
</div>
|
||||
{/each}
|
||||
@@ -783,7 +808,7 @@
|
||||
</span>
|
||||
</span>
|
||||
</span>
|
||||
<span class="label">All Repos</span>
|
||||
<span class="label">Seeded Repos</span>
|
||||
{#if !sidebarCollapsed.value && unpinnedReposCount > 1}
|
||||
<span
|
||||
class="global-counter-badge"
|
||||
@@ -921,7 +946,8 @@
|
||||
data-unpinned-rid={repo.rid}
|
||||
animate:flip={{ duration: animationDuration }}
|
||||
in:receive={{ key: repo.rid, duration: animationDuration }}
|
||||
out:send={{ key: repo.rid, duration: animationDuration }}>
|
||||
out:send={{ key: repo.rid, duration: animationDuration }}
|
||||
onoutroend={() => clearUnseeding(repo.rid)}>
|
||||
{@render repoRowInner(repo, false)}
|
||||
</div>
|
||||
{/each}
|
||||
|
||||
+1
-1
@@ -224,7 +224,7 @@ export const cachedGetCommitDiff = cached(
|
||||
* unseeding) go through invalidateReposSummary().
|
||||
*/
|
||||
export const cachedListReposSummary = cached(
|
||||
() => invoke<RepoSummary[]>("list_repos_summary"),
|
||||
() => invoke<RepoSummary[]>("list_repos_summary", { show: "seeded" }),
|
||||
() => "list_repos_summary",
|
||||
{ max: 1, ttl: 30_000 },
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user