From 6c8875317921025dbe59fee4bb6fc71663a91bac Mon Sep 17 00:00:00 2001 From: soul Date: Sat, 28 Nov 2026 00:25:38 +0100 Subject: [PATCH] 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 --- tools/AetherDb/ShipAuthoringCommands.cs | 24 +++++++++++++----------- tools/AetherDb/ShipAuthoringPush.cs | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/tools/AetherDb/ShipAuthoringCommands.cs b/tools/AetherDb/ShipAuthoringCommands.cs index 1b9de869b..328ed34e9 100644 --- a/tools/AetherDb/ShipAuthoringCommands.cs +++ b/tools/AetherDb/ShipAuthoringCommands.cs @@ -208,18 +208,20 @@ public static class ShipAuthoringCommands } 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 - // kind rule judges it against the shipped catalog, read-only, before the file is opened writable. - var (hull, ship, _) = ShipAuthoringStore.Load(args[1]); - hull.Kind = new CultRecordRef(StationKindData.KeyOf(args[2])); + // A thin builder over the push core: load through the cache the push loads from, derive the hull with its kind, judge + // it by the one kind rule against the shipped catalog (read-only), and commit through Land, the push's compare-exchange + // path, so a hull written since the load is refused as stale and the file stays as it was. + 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.KeyOf(args[2])); using (var catalog = AetherDb.Open().Cache) - if (StationKinds.HullKindFault(catalog, hull) is { } fault) throw new InvalidOperationException($"{ship.Id}: {fault}"); - using (var cache = ShipAuthoringStore.Open(args[1], writable: true)) - { - ShipAuthoringStore.Write(cache, hull, ship); - cache.FlushAsync().Wait(); - } - Console.WriteLine($"{ship.Id}: kind {hull.Kind.Key.Value}."); + if (StationKinds.HullKindFault(catalog, derived) is { } fault) throw new InvalidOperationException($"{ship.Id}: {fault}"); + var key = ShipModCatalog.HullKey(ship.Id); + if (!ShipAuthoringPush.Land(cache, new[] { new ShipAuthoringPush.Write(key, typeof(HullData), hull, derived) })) + throw new InvalidOperationException($"{ship.Id}: the hull was written since it was loaded; nothing was changed."); + cache.FlushAsync().Wait(); + Console.WriteLine($"{ship.Id}: kind {derived.Kind.Key.Value}."); return 0; } Console.Error.WriteLine(Usage); diff --git a/tools/AetherDb/ShipAuthoringPush.cs b/tools/AetherDb/ShipAuthoringPush.cs index 1ac8a7126..016ff3d93 100644 --- a/tools/AetherDb/ShipAuthoringPush.cs +++ b/tools/AetherDb/ShipAuthoringPush.cs @@ -90,7 +90,7 @@ public static class ShipAuthoringPush private static byte[] Pack(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. - private static T Copy(T value) => MessagePackSerializer.Deserialize(Pack(value), PackOptions); + internal static T Copy(T value) => MessagePackSerializer.Deserialize(Pack(value), PackOptions); // The request that, pushed back unchanged, changes nothing. public static int Open(string path, TextWriter output)