pub fn sweep_orphaned_account_dirs(
store: &Store,
identities_root: &Path,
min_age_secs: u64,
) -> Vec<PathBuf>Expand description
Sweep identities_root’s direct children for orphaned per-account
dirs: compute_and_ensure_account_dir mints a fresh <account_id>/
dir and writes real credential files into it BEFORE the login that
dir belongs to ever completes, so no IdentityAccount row exists yet
to reference it. A login that’s abandoned, times out, or crashes the
app mid-flow leaves that directory behind forever — reagent’s finding
on #2260: “abandoned/failed attempts leave orphaned directories with
no cleanup path.”
Called opportunistically from compute_and_ensure_account_dir right
before every FRESH mint (never on a reconnect — reusing an existing
account’s dir needs no sweep). Age-gated via min_age_secs so a
login that’s still genuinely in progress — which legitimately has no
DB row yet either — is never swept out from under it; callers should
pick a margin comfortably above every frontend poll timeout (5
minutes as of this writing) to leave room for a slow user plus retry.
Best-effort and silent-safe: identity_get failures or an unreadable
root skip that candidate (or the whole sweep) rather than risk
deleting a real, in-use account’s dir on a false read. Returns the
dirs actually removed, mainly for tests to assert on.