From 4edb0374fcca20f7412f066a990ade8217451d87 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 21 Jul 2024 21:14:27 +0300 Subject: [PATCH] server: Fix "Content hash check for [...] sector [...] FAILED" The issue was caused by a guard condition which prevented the writing of entity changes which came from the remote and were marked as deleted, resulting in an incorrect checksum when attempting to sync. --- src/services/sync_update.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/services/sync_update.ts b/src/services/sync_update.ts index 78a6f3f278..61d4254382 100644 --- a/src/services/sync_update.ts +++ b/src/services/sync_update.ts @@ -41,15 +41,13 @@ function updateEntities(entityChanges: EntityChangeRecord[], instanceId: string) atLeastOnePullApplied = true; } - if (entity) { - updateEntity(entityChange, entity, instanceId, updateContext); - } + updateEntity(entityChange, entity, instanceId, updateContext); } logUpdateContext(updateContext); } -function updateEntity(remoteEC: EntityChange, remoteEntityRow: EntityRow, instanceId: string, updateContext: UpdateContext) { +function updateEntity(remoteEC: EntityChange, remoteEntityRow: EntityRow | undefined, instanceId: string, updateContext: UpdateContext) { if (!remoteEntityRow && remoteEC.entityName === 'options') { return; // can be undefined for options with isSynced=false } @@ -74,7 +72,7 @@ function updateEntity(remoteEC: EntityChange, remoteEntityRow: EntityRow, instan } } -function updateNormalEntity(remoteEC: EntityChange, remoteEntityRow: EntityRow, instanceId: string, updateContext: UpdateContext) { +function updateNormalEntity(remoteEC: EntityChange, remoteEntityRow: EntityRow | undefined, instanceId: string, updateContext: UpdateContext) { const localEC = sql.getRow(`SELECT * FROM entity_changes WHERE entityName = ? AND entityId = ?`, [remoteEC.entityName, remoteEC.entityId]); const localECIsOlderOrSameAsRemote = ( localEC && localEC.utcDateChanged && remoteEC.utcDateChanged && @@ -139,7 +137,7 @@ function preProcessContent(remoteEC: EntityChange, remoteEntityRow: EntityRow) { } } -function updateNoteReordering(remoteEC: EntityChange, remoteEntityRow: EntityRow, instanceId: string) { +function updateNoteReordering(remoteEC: EntityChange, remoteEntityRow: EntityRow | undefined, instanceId: string) { if (!remoteEntityRow) { throw new Error(`Empty note_reordering body for: ${JSON.stringify(remoteEC)}`); }