CultMesh: a raw write refuses a file whose header it cannot read

ExistingHeader read the whole snapshot and swallowed every failure into "no header": a
truncated v3 file got a v1 raw write and an unknown v9 file was overwritten, where
TypeScript, Python and Rust refuse. CultDocumentMessagePackSerialization.ReadStoreHeader
reads the prefix header, refuses a file that is not one complete MessagePack value or whose
format this runtime cannot read, and the raw write keeps a whole marked file marked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-29 22:53:13 +02:00
commit aa6b11006f
3 changed files with 58 additions and 8 deletions

View file

@ -268,14 +268,8 @@ namespace GameCult.Mesh
private static string? ExistingHeader(string path)
{
try
{
return CultDocumentMessagePackSerialization.DeserializeSnapshot(File.ReadAllBytes(path)).FormatVersion;
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or MessagePackSerializationException or EndOfStreamException or InvalidOperationException or NotSupportedException)
{
return null;
}
// A file that is gone has no header; one that cannot be read refuses the write rather than being overwritten.
return File.Exists(path) ? CultDocumentMessagePackSerialization.ReadStoreHeader(File.ReadAllBytes(path)) : null;
}
private static CultPersistedStoreSnapshot ReadSingleFileSnapshot(string path)