diff --git a/crates/coremem/src/render.rs b/crates/coremem/src/render.rs index 7ae7e46..b56a033 100644 --- a/crates/coremem/src/render.rs +++ b/crates/coremem/src/render.rs @@ -640,9 +640,12 @@ impl SerializerRenderer { measurements, }; let name = self.fmt_str.replace("{step_no}", &*frame.state.step_no().to_string()); - let out = BufWriter::new(File::create(name).unwrap()); - //serde_cbor::to_writer(out, &snap).unwrap(); + // serialize to a temporary file -- in case we run out of disk space, etc. + let temp_name = format!("{}.incomplete", name); + let out = BufWriter::new(File::create(&temp_name).unwrap()); bincode::serialize_into(out, &frame).unwrap(); + // atomically complete the write. + std::fs::rename(temp_name, name).unwrap(); } pub fn try_load Deserialize<'a>>(&self) -> Option> {