Skip to content

Commit a0781ff

Browse files
committed
fix(Scanner#diffFolder): Fallback to full scan if no fuzzy match is found
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
1 parent 9a37a34 commit a0781ff

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

src/lib/Scanner.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,13 @@ export default class Scanner<L1 extends TItemLocation, L2 extends TItemLocation>
132132
// Optimization: Use a Map for O(1) lookups
133133
const unmatchedMap = new Map<string, TItem<L2>[]>()
134134
for (const child of newFolder.children) {
135-
const key = `${child.type}_${child.title}` // Or a better unique key based on mergeable logic
135+
const key = `${child.type}_${child.title}`
136136
const list = unmatchedMap.get(key) || []
137137
list.push(child)
138138
unmatchedMap.set(key, list)
139139
}
140140
const stillUnmatched = new Set(newFolder.children)
141141

142-
// (using map here, because 'each' doesn't provide indices)
143142
let index = 0
144143
for (const old of oldFolder.children) {
145144
const key = `${old.type}_${old.title}`
@@ -151,16 +150,16 @@ export default class Scanner<L1 extends TItemLocation, L2 extends TItemLocation>
151150
)
152151
if (matchIndex !== -1) {
153152
newItem = potentialMatches.splice(matchIndex, 1)[0]
154-
stillUnmatched.delete(newItem)
155153
}
156-
} else {
154+
}
155+
if (!newItem) {
157156
newItem = newFolder.children.find(
158157
(child) => old.type === child.type && this.mergeable(old, child)
159158
)
160-
if (newItem) stillUnmatched.delete(newItem)
161159
}
162160
// we found an item in the new folder that matches the one in the old folder
163161
if (newItem) {
162+
stillUnmatched.delete(newItem)
164163
await this.diffItem(old, newItem)
165164
index++
166165
continue
@@ -378,7 +377,7 @@ export default class Scanner<L1 extends TItemLocation, L2 extends TItemLocation>
378377
if (oldItem === removedRoot) {
379378
this.result.REMOVE.retract(removeRootAction)
380379
} else {
381-
const clone = (removedRoot as Folder<L1>).clone(true)
380+
const clone = (removedRoot as Folder<L1>).clone(false)
382381
const parentClone = clone.findItem(
383382
ItemType.FOLDER,
384383
oldItem.parentId
@@ -511,7 +510,7 @@ export default class Scanner<L1 extends TItemLocation, L2 extends TItemLocation>
511510
if (oldItem === removedRoot) {
512511
this.result.REMOVE.retract(removeRootAction)
513512
} else {
514-
const clone = (removedRoot as Folder<L1>).clone(true)
513+
const clone = (removedRoot as Folder<L1>).clone(false)
515514
const parentClone = clone.findItem(
516515
ItemType.FOLDER,
517516
oldItem.parentId
@@ -529,7 +528,7 @@ export default class Scanner<L1 extends TItemLocation, L2 extends TItemLocation>
529528
if (createdItem === createdRoot) {
530529
this.result.CREATE.retract(createRootAction)
531530
} else {
532-
const clone = (createdRoot as Folder<L2>).clone(true)
531+
const clone = (createdRoot as Folder<L2>).clone(false)
533532
const parentClone = clone.findItem(
534533
ItemType.FOLDER,
535534
createdItem.parentId

0 commit comments

Comments
 (0)