commit c92508b66b34ccf0f94e7d5a030c6686fb211b5b
parent 236e366a9c8b43b9e9ac40f205807794c1734f4d
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date: Mon, 21 Oct 2024 15:38:18 -0700
Ensure ID maps are valid
This prevents IDs from being mapped to more than one other ID.
Diffstat:
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/files/floorplans/floorplan/backend.js b/files/floorplans/floorplan/backend.js
@@ -998,8 +998,24 @@ export class FloorplanBackend {
if (localID == null || serverID == null) {
throw new Error("Requires local and server ID")
}
+
+ for (let lid in this.serverIDs) {
+ let sid = this.serverIDs[lid]
+ if (sid != null && this.localIDs[sid] !== lid) {
+ console.error("Corrupt ID map", structuredClone({ bsid: sid, blid: lid, server: this.serverIDs, local: this.localIDs }))
+ throw new Error("ID map is corrupted")
+ }
+ }
+ for (let sid in this.localIDs) {
+ let lid = this.localIDs[sid]
+ if (this.serverIDs[sid] != null || this.serverIDs[lid] !== sid) {
+ console.error("Corrupt ID map", structuredClone({ bsid: sid, blid: lid, server: this.serverIDs, local: this.localIDs }))
+ throw new Error("ID map is corrupted")
+ }
+ }
+
if (options.remap) {
- delete this.serverIDs[localID]
+ this.serverIDs[localID] = null
} else {
if (this.serverIDs[localID] != undefined) {
throw new Error("That local ID is already mapped to " + this.serverIDs[localID])