424
}
425
}
427
>
// Otherwise keep
428
>
else {
429
>
keepEvent = true;
430
>
}
431
>
432
>
if (keepEvent) {
433
>
this.coalesced.add(event);
434
>
this.mapPathToChange.set(this.toKey(event), event);
435
>
}
436
>
}
437
438
coalesce(): IFileChange[] {
439
>
const addOrChangeEvents: IFileChange[] = [];
watcher.ts
440
>
const deletedPaths: string[] = [];
441
>
442
>
// This algorithm will remove all DELETE events up to the root folder
443
>
// that got deleted if any. This ensures that we are not producing
444
>
// DELETE events for each file inside a folder that gets deleted.
445
>
//
446
>
// 1.) split ADD/CHANGE and DELETED events
447
>
// 2.) sort short deleted paths to the top
448
>
// 3.) for each DELETE, check if there is a deleted parent and ignore the event in that case
449
>
return Array.from(this.coalesced).filter(e => {
450
>
if (e.type !== FileChangeType.DELETED) {
451
>
addOrChangeEvents.push(e);
452
>
453
>
return false; // remove ADD / CHANGE
454
>
}
455
456
return true; // keep DELETE
458
return e1.resource.fsPath.length - e2.resource.fsPath.length; // shortest path first
460
if (deletedPaths.some(deletedPath => isParent(e.resource.fsPath, deletedPath, !isLinux /* ignorecase */))) {
461
return false; // DELETE is ignored if parent is deleted already