From 7aeea0f75cde3124151d4f1eec988e98f5a7ecf5 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Sun, 24 Nov 2024 19:28:58 +0100 Subject: [PATCH] fix(Scanner): Fix move stability Signed-off-by: Marcel Klehr --- src/lib/Scanner.ts | 8 ++++++-- src/lib/strategies/Merge.ts | 3 +++ src/lib/strategies/Unidirectional.ts | 2 ++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/lib/Scanner.ts b/src/lib/Scanner.ts index 47e133ecb1..9b67328ebe 100644 --- a/src/lib/Scanner.ts +++ b/src/lib/Scanner.ts @@ -17,15 +17,17 @@ export default class Scanner private mergeable: (i1: TItem, i2: TItem) => boolean private preserveOrder: boolean private checkHashes: boolean + private hasCache: boolean private result: ScanResult - constructor(oldTree:TItem, newTree:TItem, mergeable:(i1:TItem, i2:TItem)=>boolean, preserveOrder:boolean, checkHashes = true) { + constructor(oldTree:TItem, newTree:TItem, mergeable:(i1:TItem, i2:TItem)=>boolean, preserveOrder:boolean, checkHashes = true, hasCache = true) { this.oldTree = oldTree this.newTree = newTree this.mergeable = mergeable this.preserveOrder = preserveOrder this.checkHashes = typeof checkHashes === 'undefined' ? true : checkHashes + this.hasCache = hasCache this.result = { CREATE: new Diff(), UPDATE: new Diff(), @@ -159,7 +161,9 @@ export default class Scanner await Promise.resolve() const removedItem = removeAction.payload - if (this.mergeable(removedItem, createdItem) && (removedItem.type !== 'folder' || removedItem.childrenSimilarity(createdItem) > 0.8)) { + if (this.mergeable(removedItem, createdItem) && + (removedItem.type !== 'folder' || + (!this.hasCache && removedItem.childrenSimilarity(createdItem) > 0.8))) { this.result.CREATE.retract(createAction) this.result.REMOVE.retract(removeAction) this.result.MOVE.commit({ diff --git a/src/lib/strategies/Merge.ts b/src/lib/strategies/Merge.ts index e2c4c411a0..c98670ef61 100644 --- a/src/lib/strategies/Merge.ts +++ b/src/lib/strategies/Merge.ts @@ -23,6 +23,7 @@ export default class MergeSyncProcess extends DefaultSyncProcess { return false }, this.preserveOrder, + false, false ) const serverScanner = new Scanner( @@ -36,6 +37,7 @@ export default class MergeSyncProcess extends DefaultSyncProcess { return false }, this.preserveOrder, + false, false ) const localScanResult = await localScanner.run() @@ -96,6 +98,7 @@ export default class MergeSyncProcess extends DefaultSyncProcess { return false }, this.preserveOrder, + false, false ) await subScanner.run() diff --git a/src/lib/strategies/Unidirectional.ts b/src/lib/strategies/Unidirectional.ts index 0b83028a6a..8f4f145889 100644 --- a/src/lib/strategies/Unidirectional.ts +++ b/src/lib/strategies/Unidirectional.ts @@ -51,6 +51,7 @@ export default class UnidirectionalSyncProcess extends DefaultStrategy { return false }, this.preserveOrder, + false, false ) const serverScanner = new Scanner( @@ -64,6 +65,7 @@ export default class UnidirectionalSyncProcess extends DefaultStrategy { return false }, this.preserveOrder, + false, false ) const localScanResult = await localScanner.run()