Skip to content

Commit

Permalink
fix(Scanner): Fix move stability
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
  • Loading branch information
marcelklehr committed Nov 24, 2024
1 parent d3015b2 commit 7aeea0f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/lib/Scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@ export default class Scanner<L1 extends TItemLocation, L2 extends TItemLocation>
private mergeable: (i1: TItem<TItemLocation>, i2: TItem<TItemLocation>) => boolean
private preserveOrder: boolean
private checkHashes: boolean
private hasCache: boolean

private result: ScanResult<L2, L1>

constructor(oldTree:TItem<L1>, newTree:TItem<L2>, mergeable:(i1:TItem<TItemLocation>, i2:TItem<TItemLocation>)=>boolean, preserveOrder:boolean, checkHashes = true) {
constructor(oldTree:TItem<L1>, newTree:TItem<L2>, mergeable:(i1:TItem<TItemLocation>, i2:TItem<TItemLocation>)=>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(),
Expand Down Expand Up @@ -159,7 +161,9 @@ export default class Scanner<L1 extends TItemLocation, L2 extends TItemLocation>
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({
Expand Down
3 changes: 3 additions & 0 deletions src/lib/strategies/Merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default class MergeSyncProcess extends DefaultSyncProcess {
return false
},
this.preserveOrder,
false,
false
)
const serverScanner = new Scanner(
Expand All @@ -36,6 +37,7 @@ export default class MergeSyncProcess extends DefaultSyncProcess {
return false
},
this.preserveOrder,
false,
false
)
const localScanResult = await localScanner.run()
Expand Down Expand Up @@ -96,6 +98,7 @@ export default class MergeSyncProcess extends DefaultSyncProcess {
return false
},
this.preserveOrder,
false,
false
)
await subScanner.run()
Expand Down
2 changes: 2 additions & 0 deletions src/lib/strategies/Unidirectional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export default class UnidirectionalSyncProcess extends DefaultStrategy {
return false
},
this.preserveOrder,
false,
false
)
const serverScanner = new Scanner(
Expand All @@ -64,6 +65,7 @@ export default class UnidirectionalSyncProcess extends DefaultStrategy {
return false
},
this.preserveOrder,
false,
false
)
const localScanResult = await localScanner.run()
Expand Down

0 comments on commit 7aeea0f

Please sign in to comment.