Mesh single-file helpers read and replace through the CultCache single-file store; a directory at the store path is an error
SingleFileBackingStore gains ReadDurable and ReplaceDurable (internal): CultMesh's read and write helpers reach the one reader, <file>.lock and the unique-temp atomic replace through them. ReadDisk decides absence from the path's attributes, so a directory at the path is an IOException, not an empty store. Includes the directory clause that the spec lists as a separate step. Builds with the previous commit's deletions; the tree before this commit does not build. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
2e12e9eebb
commit
9852fa9367
2 changed files with 28 additions and 10 deletions
|
|
@ -161,7 +161,7 @@ namespace GameCult.Mesh
|
|||
if (string.IsNullOrWhiteSpace(path)) throw new ArgumentException("Value must be non-empty.", nameof(path));
|
||||
if (string.IsNullOrWhiteSpace(expectedSchemaId)) throw new ArgumentException("Value must be non-empty.", nameof(expectedSchemaId));
|
||||
|
||||
var snapshot = ReadSingleFileSnapshot(path);
|
||||
var snapshot = StoreAt(path).ReadDurable() ?? throw new FileNotFoundException($"CultCache document '{path}' does not exist.", path);
|
||||
var record = snapshot.Records.SingleOrDefault(candidate => string.Equals(candidate.Key, key.Value, StringComparison.Ordinal))
|
||||
?? throw new InvalidDataException($"CultCache document '{path}' does not contain record '{key.Value}'.");
|
||||
|
||||
|
|
@ -192,7 +192,7 @@ namespace GameCult.Mesh
|
|||
if (string.IsNullOrWhiteSpace(path)) throw new ArgumentException("Value must be non-empty.", nameof(path));
|
||||
if (string.IsNullOrWhiteSpace(expectedSchemaId)) throw new ArgumentException("Value must be non-empty.", nameof(expectedSchemaId));
|
||||
|
||||
var snapshot = ReadSingleFileSnapshot(path);
|
||||
var snapshot = StoreAt(path).ReadDurable() ?? throw new FileNotFoundException($"CultCache document '{path}' does not exist.", path);
|
||||
if (snapshot.Records.Length != 1)
|
||||
{
|
||||
throw new InvalidDataException(
|
||||
|
|
@ -239,11 +239,10 @@ namespace GameCult.Mesh
|
|||
throw new ArgumentException("Catalog entry must include a schema id.", nameof(catalogEntry));
|
||||
|
||||
payload ??= Array.Empty<byte>();
|
||||
CultPersistedStoreSnapshot? existing = null;
|
||||
|
||||
// A typed write sees the document it replaces the file with, so its ids decide. A raw payload is opaque: the writer
|
||||
// cannot see whether it holds ids, so a file already marked stays marked.
|
||||
var snapshot = new CultPersistedStoreSnapshot
|
||||
// cannot see whether it holds ids, so a file already marked stays marked. The store reads the file it replaces under
|
||||
// its lock: one this runtime cannot read refuses the write instead of being overwritten.
|
||||
StoreAt(path).ReplaceDurable(existing => new CultPersistedStoreSnapshot
|
||||
{
|
||||
FormatVersion = CacheBackingStore.HeaderFor(holdsIds, existing?.FormatVersion, wholeStore: contentKnown, directoryStore: false),
|
||||
SchemaCatalog = new[] { catalogEntry },
|
||||
|
|
@ -257,10 +256,11 @@ namespace GameCult.Mesh
|
|||
Payload = payload
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private static SingleFileMessagePackBackingStore StoreAt(string path) => new SingleFileMessagePackBackingStore(path);
|
||||
|
||||
private static bool PublishesSchema(CultSchemaCatalogEntry[] catalog, string schemaId)
|
||||
{
|
||||
return catalog.Any(entry =>
|
||||
|
|
|
|||
Loading…
Reference in a new issue