Skip to content

Commit

Permalink
server: Fix "Content hash check for [...] sector [...] FAILED"
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
eliandoran committed Jul 21, 2024
1 parent 2e9a624 commit 4edb037
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/services/sync_update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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<EntityChange | undefined>(`SELECT * FROM entity_changes WHERE entityName = ? AND entityId = ?`, [remoteEC.entityName, remoteEC.entityId]);
const localECIsOlderOrSameAsRemote = (
localEC && localEC.utcDateChanged && remoteEC.utcDateChanged &&
Expand Down Expand Up @@ -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)}`);
}
Expand Down

0 comments on commit 4edb037

Please sign in to comment.