Skip to content

Commit 922af60

Browse files
committed
fix(ev-deployer): use atomic writes for deploy state file
Write to a .tmp file first, then rename into place. Prevents state file corruption if the process crashes mid-write.
1 parent 77c098b commit 922af60

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

bin/ev-deployer/src/deploy/state.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,12 @@ impl DeployState {
8686
Ok(state)
8787
}
8888

89-
/// Save state to a JSON file.
89+
/// Save state to a JSON file atomically (write to tmp, then rename).
9090
pub(crate) fn save(&self, path: &Path) -> eyre::Result<()> {
9191
let json = serde_json::to_string_pretty(self)?;
92-
std::fs::write(path, json)?;
92+
let tmp = path.with_extension("tmp");
93+
std::fs::write(&tmp, &json)?;
94+
std::fs::rename(&tmp, path)?;
9395
Ok(())
9496
}
9597

0 commit comments

Comments
 (0)