1
0

Update file monitoring to ignore additional directories and implement file limit check

This commit is contained in:
Victor Giers
2025-11-27 11:27:44 +01:00
parent 511eef1e55
commit c10fafb4fa

46
main.js
View File

@@ -658,6 +658,11 @@ const monitoringActive = new Map(); // Map: folderPath -> Boolean (ob Task aktiv
const MONITOR_DEFAULT_IGNORES = [ const MONITOR_DEFAULT_IGNORES = [
'.git', '.git',
'node_modules', 'node_modules',
'.venv',
'venv',
'__pycache__',
'.mypy_cache',
'.pytest_cache',
'dist', 'dist',
'build', 'build',
'out', 'out',
@@ -666,10 +671,14 @@ const MONITOR_DEFAULT_IGNORES = [
'.turbo', '.turbo',
'.parcel-cache', '.parcel-cache',
'.cache', '.cache',
'target',
'src-tauri/target',
'coverage', 'coverage',
'logs', 'logs',
'tmp', 'tmp',
'temp', 'temp',
'output',
'tmp*',
'*.log', '*.log',
'*.tmp', '*.tmp',
'*.swp' '*.swp'
@@ -713,6 +722,32 @@ function ensureInGitignore(folderPath, name, igInstance) {
return true; return true;
} }
function exceedsFileLimit(folderPath, igInstance, limit = 20000) {
let count = 0;
const stack = [folderPath];
while (stack.length) {
const current = stack.pop();
let entries = [];
try {
entries = fs.readdirSync(current, { withFileTypes: true });
} catch (_) {
continue;
}
for (const dirent of entries) {
const full = path.join(current, dirent.name);
const rel = path.relative(folderPath, full);
if (rel && igInstance.ignores(rel)) continue;
if (dirent.isDirectory()) {
stack.push(full);
} else {
count++;
if (count > limit) return true;
}
}
}
return false;
}
function startMonitoringWatcher(folderPath, win) { function startMonitoringWatcher(folderPath, win) {
if (monitoringWatchers.has(folderPath)) return; if (monitoringWatchers.has(folderPath)) return;
@@ -739,6 +774,17 @@ function startMonitoringWatcher(folderPath, win) {
} }
// 3. Create the watcher, now with deep ignore support! // 3. Create the watcher, now with deep ignore support!
if (exceedsFileLimit(folderPath, ig)) {
debug(`[MONITOR] Skipping watcher for ${folderPath}: too many files (limit reached)`);
let folders = store.get('folders') || [];
folders = folders.map(f =>
f.path === folderPath ? { ...f, monitoring: false } : f
);
store.set('folders', folders);
win.webContents.send('monitoring-error', { path: folderPath, code: 'TOO_MANY_FILES' });
return;
}
const watcher = chokidar.watch(folderPath, { const watcher = chokidar.watch(folderPath, {
ignored: ignoredFunc, ignored: ignoredFunc,
ignoreInitial: true, ignoreInitial: true,