fix(#1201): prevent sync_agents from dropping all agents on list() failure
This commit is contained in:
parent
4d1ce6f313
commit
cff3b6ff85
2 changed files with 23 additions and 1 deletions
|
|
@ -80,6 +80,21 @@ pub async fn sync_agents(
|
|||
return Ok(());
|
||||
}
|
||||
|
||||
// Safety guard: refuse to write an empty agent list over a non-empty
|
||||
// on-disk flake. An empty `agents` slice is never intentional — it
|
||||
// means `nixos-container list` failed and the caller got an empty
|
||||
// fallback. Overwriting here would drop every agent from the meta
|
||||
// flake and trigger unnecessary (and potentially destructive) cascade
|
||||
// rebuilds. Callers that genuinely need to clear the agent list
|
||||
// (there are none today) must handle this case explicitly.
|
||||
if agents.is_empty() && !initial && !on_disk.is_empty() {
|
||||
tracing::warn!(
|
||||
"sync_agents: refusing to overwrite non-empty meta flake with empty agent list \
|
||||
(nixos-container list may have failed)"
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
std::fs::write(&flake_path, &new_flake)
|
||||
.with_context(|| format!("write {}", flake_path.display()))?;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue