ship-authoring kind commits through the push core's Land
A thin builder: loads through the cache, derives the hull with its kind, judges by HullKindFault and lands with the push's compare-exchange, so a stale write is refused. Not a direct cache writer. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
86628d45ac
commit
6c88753179
2 changed files with 14 additions and 12 deletions
|
|
@ -208,18 +208,20 @@ public static class ShipAuthoringCommands
|
||||||
}
|
}
|
||||||
if (args[0] == "kind" && args.Length == 3)
|
if (args[0] == "kind" && args.Length == 3)
|
||||||
{
|
{
|
||||||
// The one writer of a station package's Kind, beside push (the scene's writer): same loader, one commit. The one
|
// A thin builder over the push core: load through the cache the push loads from, derive the hull with its kind, judge
|
||||||
// kind rule judges it against the shipped catalog, read-only, before the file is opened writable.
|
// it by the one kind rule against the shipped catalog (read-only), and commit through Land, the push's compare-exchange
|
||||||
var (hull, ship, _) = ShipAuthoringStore.Load(args[1]);
|
// path, so a hull written since the load is refused as stale and the file stays as it was.
|
||||||
hull.Kind = new CultRecordRef<StationKindData>(StationKindData.KeyOf(args[2]));
|
using var cache = ShipAuthoringStore.Open(args[1], writable: true);
|
||||||
|
var (hull, ship, _) = ShipAuthoringStore.Load(cache, args[1]);
|
||||||
|
var derived = ShipAuthoringPush.Copy(hull);
|
||||||
|
derived.Kind = new CultRecordRef<StationKindData>(StationKindData.KeyOf(args[2]));
|
||||||
using (var catalog = AetherDb.Open().Cache)
|
using (var catalog = AetherDb.Open().Cache)
|
||||||
if (StationKinds.HullKindFault(catalog, hull) is { } fault) throw new InvalidOperationException($"{ship.Id}: {fault}");
|
if (StationKinds.HullKindFault(catalog, derived) is { } fault) throw new InvalidOperationException($"{ship.Id}: {fault}");
|
||||||
using (var cache = ShipAuthoringStore.Open(args[1], writable: true))
|
var key = ShipModCatalog.HullKey(ship.Id);
|
||||||
{
|
if (!ShipAuthoringPush.Land(cache, new[] { new ShipAuthoringPush.Write(key, typeof(HullData), hull, derived) }))
|
||||||
ShipAuthoringStore.Write(cache, hull, ship);
|
throw new InvalidOperationException($"{ship.Id}: the hull was written since it was loaded; nothing was changed.");
|
||||||
cache.FlushAsync().Wait();
|
cache.FlushAsync().Wait();
|
||||||
}
|
Console.WriteLine($"{ship.Id}: kind {derived.Kind.Key.Value}.");
|
||||||
Console.WriteLine($"{ship.Id}: kind {hull.Kind.Key.Value}.");
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Console.Error.WriteLine(Usage);
|
Console.Error.WriteLine(Usage);
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ public static class ShipAuthoringPush
|
||||||
private static byte[] Pack<T>(T value) => MessagePackSerializer.Serialize(value, PackOptions);
|
private static byte[] Pack<T>(T value) => MessagePackSerializer.Serialize(value, PackOptions);
|
||||||
|
|
||||||
// A deep copy by the type's own MessagePack round trip, as HullLike copies a hull: a member added later is copied too.
|
// A deep copy by the type's own MessagePack round trip, as HullLike copies a hull: a member added later is copied too.
|
||||||
private static T Copy<T>(T value) => MessagePackSerializer.Deserialize<T>(Pack(value), PackOptions);
|
internal static T Copy<T>(T value) => MessagePackSerializer.Deserialize<T>(Pack(value), PackOptions);
|
||||||
|
|
||||||
// The request that, pushed back unchanged, changes nothing.
|
// The request that, pushed back unchanged, changes nothing.
|
||||||
public static int Open(string path, TextWriter output)
|
public static int Open(string path, TextWriter output)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue