diff --git a/crates/grove-daemon/src/daemon.rs b/crates/grove-daemon/src/daemon.rs index 994212d..6260fd8 100644 --- a/crates/grove-daemon/src/daemon.rs +++ b/crates/grove-daemon/src/daemon.rs @@ -666,6 +666,13 @@ fn pass( } } } + if !errors.is_empty() && !is_ready(repo) { + // The directory vanished (or stopped being a bare layout) mid-pass: the failure is a + // consequence of the removal, not a sync error. Rediscovery drops the repo and logs + // `repo_removed`. + status.phase = "idle"; + return 0; + } if offline { // A snapshot-only pass during backoff changes neither the failure count nor the phase. status.phase = if status.failures > 0 { "error" } else { "idle" }; @@ -726,6 +733,7 @@ fn purge_snapshots(ctx: &Ctx, repo: &Path, name: &str, cfg: &Config, st: &Settin done.join(", ") ), ), + Err(_) if !is_ready(repo) => {} // removed mid-pass: rediscovery reports it Err(e) => ctx.activity.log( "error", Some(name), diff --git a/crates/grove-daemon/tests/daemon.rs b/crates/grove-daemon/tests/daemon.rs index 9e8bd8b..1500b7d 100644 --- a/crates/grove-daemon/tests/daemon.rs +++ b/crates/grove-daemon/tests/daemon.rs @@ -610,7 +610,11 @@ fn managed_repo_removed_after_start_disappears_without_crash() { // Keep the first repo busy so a pass may be running when the other one vanishes. fs::write(root.join("g/repo/main/busy.txt"), "x\n").unwrap(); - fs::remove_dir_all(root.join("g/second")).unwrap(); + // The daemon may create files in the repo while it is being deleted (ENOTEMPTY): retry. + wait_until("repo directory removed", 5, || { + let _ = fs::remove_dir_all(root.join("g/second")); + !root.join("g/second").exists() + }); wait_until("removed repo dropped", 10, || { repo_paths(&sock) == vec![root.join("g/repo").display().to_string()] });