core: write persisted snapshots atomically (temp + rename) so a crash mid-write can't leave a truncated reputation/metadata/xline file

This commit is contained in:
Jean Chevronnet 2026-08-12 15:57:43 +00:00
parent 859450fb6c
commit b022189fa5

View file

@ -515,7 +515,13 @@ impl Server {
std::mem::take(&mut *map) // drain, releasing the lock before writing
};
for (path, contents) in batch {
let _ = std::fs::write(path, contents);
// write a sibling temp then rename over the target: rename is
// atomic, so a crash mid-write can never leave a truncated
// snapshot — the file on disk is always a complete prior state.
let tmp = format!("{path}.tmp");
if std::fs::write(&tmp, &contents).is_ok() {
let _ = std::fs::rename(&tmp, &path);
}
}
}
});