fix: track pending folder reservations

This commit is contained in:
Sucukdeluxe
2026-08-26 09:39:18 +02:00
parent d16823acbc
commit 7890292d96
2 changed files with 49 additions and 2 deletions
+13 -2
View File
@@ -30,6 +30,7 @@ class FolderMonitor extends EventEmitter {
this._settings = null;
this._seenFiles = new Set();
this._batchBuffer = [];
this._batchSeenReservations = new Set();
this._batchTimer = null;
this._initialScopes = new Set();
this._reconcileTimer = null;
@@ -189,8 +190,9 @@ class FolderMonitor extends EventEmitter {
_invalidateLifecycle(paused) {
this._generation++;
if (paused) {
for (const filePath of this._batchBuffer) this._seenFiles.delete(this._normalizePath(filePath));
for (const normalized of this._batchSeenReservations) this._seenFiles.delete(normalized);
}
this._batchSeenReservations.clear();
this._paused = paused;
this._scanning = false;
this._followUpRequested = false;
@@ -213,7 +215,11 @@ class FolderMonitor extends EventEmitter {
_onNewFile(filePath, generation) {
if (!this._acceptCallback(generation)) return;
if (!this._classifyPath(filePath, this._settings).allowed || !this._acceptPath(filePath)) return;
if (!this._classifyPath(filePath, this._settings).allowed) return;
const normalized = this._normalizePath(filePath);
const ownsSeenReservation = !!this._settings?.skipDuplicates && !this._seenFiles.has(normalized);
if (!this._acceptPath(filePath)) return;
if (ownsSeenReservation) this._batchSeenReservations.add(normalized);
this._batchBuffer.push(filePath);
if (this._batchTimer) this._clearTimeout(this._batchTimer);
this._batchTimer = this._setTimeout(() => {
@@ -222,6 +228,11 @@ class FolderMonitor extends EventEmitter {
this._batchTimer = null;
if (files.length === 0) return;
const listenerError = this._emitEvent('new-files', [files], generation);
for (const emittedPath of files) {
const emittedNormalized = this._normalizePath(emittedPath);
if (!this._batchSeenReservations.delete(emittedNormalized)) continue;
if (listenerError) this._seenFiles.delete(emittedNormalized);
}
if (listenerError && this._acceptCallback(generation)) {
this._lastError = 'Ordnerüberwachung fehlgeschlagen';
this._emitStatus(generation);