Skip to content

Commit 62c81a6

Browse files
committed
Prevent infinite loops during parent directory traversal and add path validation checks
- [calculate_directory_tokens] Error calculating tokens for directory /Users/robert/Development/Amaztours/app/packages/static/.next/types Error: ENOENT: no such file or directory, scandir '/Users/robert/Development/Amaztours/app/packages/static/.next/types' [robertpiosik.gemini-coder]path must not be empty $onExtensionRuntimeError @ mainThreadExtensionService.ts:79 mainThreadExtensionService.ts:80 TypeError: path must not be empty at P ( ├── apps │ └── editor │ └── src │ ├── context │ │ ├── context-initialization.ts │ │ └── providers │ │ └── workspace │ │ ├── modules │ │ │ └── token-calculator.ts │ │ └── workspace-provider.ts │ └── extension.ts └── packages └── shared └── src └── utils └── logger.ts
1 parent 336a4ac commit 62c81a6

2 files changed

Lines changed: 26 additions & 10 deletions

File tree

‎apps/editor/src/context/providers/workspace/modules/token-calculator.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,9 @@ export class TokenCalculator implements vscode.Disposable {
362362
this._directory_file_counts.delete(dir_path)
363363
this._directory_selected_token_counts.delete(dir_path)
364364
this._directory_selected_shrink_token_counts.delete(dir_path)
365-
dir_path = path.dirname(dir_path)
365+
const next_dir_path = path.dirname(dir_path)
366+
if (next_dir_path == dir_path) break
367+
dir_path = next_dir_path
366368
}
367369
}
368370

‎apps/editor/src/context/providers/workspace/workspace-provider.ts‎

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,9 @@ export class WorkspaceProvider
250250
const workspace_root = this.get_workspace_root_for_file(file_path)
251251
while (workspace_root && dir_path.startsWith(workspace_root)) {
252252
this._update_parent_state(dir_path)
253-
dir_path = path.dirname(dir_path)
253+
const next_dir_path = path.dirname(dir_path)
254+
if (next_dir_path == dir_path) break
255+
dir_path = next_dir_path
254256
}
255257
}
256258

@@ -407,7 +409,9 @@ export class WorkspaceProvider
407409
let parent_dir = path.dirname(changed_file_path)
408410
while (parent_dir.startsWith(workspace_root)) {
409411
this._update_parent_state(parent_dir)
410-
parent_dir = path.dirname(parent_dir)
412+
const next_parent = path.dirname(parent_dir)
413+
if (next_parent == parent_dir) break
414+
parent_dir = next_parent
411415
}
412416

413417
this._on_did_change_selected_files.fire()
@@ -468,16 +472,20 @@ export class WorkspaceProvider
468472
while (dir_path.startsWith(workspace_root)) {
469473
this._token_calculator.invalidate_directory_selected_count(dir_path)
470474
await this._update_parent_state(dir_path)
471-
dir_path = path.dirname(dir_path)
475+
const next_dir_path = path.dirname(dir_path)
476+
if (next_dir_path == dir_path) break
477+
dir_path = next_dir_path
472478
}
473479

474480
this._dispatch_change_events()
475481
}
476482

477-
let dir_path = parent_dir
478-
while (dir_path.startsWith(workspace_root)) {
479-
this._token_calculator.invalidate_directory_counts(dir_path)
480-
dir_path = path.dirname(dir_path)
483+
let dir_path2 = parent_dir
484+
while (dir_path2.startsWith(workspace_root)) {
485+
this._token_calculator.invalidate_directory_counts(dir_path2)
486+
const next_dir_path2 = path.dirname(dir_path2)
487+
if (next_dir_path2 == dir_path2) break
488+
dir_path2 = next_dir_path2
481489
}
482490

483491
this._schedule_refresh()
@@ -1013,7 +1021,9 @@ export class WorkspaceProvider
10131021
while (workspace_root && dir_path.startsWith(workspace_root)) {
10141022
this._token_calculator.invalidate_directory_selected_count(dir_path)
10151023
await this._update_parent_state(dir_path)
1016-
dir_path = path.dirname(dir_path)
1024+
const next_dir_path = path.dirname(dir_path)
1025+
if (next_dir_path == dir_path) break
1026+
dir_path = next_dir_path
10171027
}
10181028

10191029
this._dispatch_change_events()
@@ -1308,7 +1318,9 @@ export class WorkspaceProvider
13081318
const workspace_root = this.get_workspace_root_for_file(file_path)
13091319
while (workspace_root && dir_path.startsWith(workspace_root)) {
13101320
await this._update_parent_state(dir_path)
1311-
dir_path = path.dirname(dir_path)
1321+
const next_dir_path = path.dirname(dir_path)
1322+
if (next_dir_path == dir_path) break
1323+
dir_path = next_dir_path
13121324
}
13131325
}
13141326

@@ -1438,12 +1450,14 @@ export class WorkspaceProvider
14381450
const workspace_root = this.get_workspace_root_for_file(file_path)
14391451
if (!workspace_root) {
14401452
const basename = path.basename(file_path)
1453+
if (!basename || basename.trim() == '') return false
14411454
if (this._user_allow_patterns.ignores(basename)) {
14421455
return false
14431456
}
14441457
return this._user_ignore_patterns.ignores(basename)
14451458
}
14461459
const relative_path = path.relative(workspace_root, file_path)
1460+
if (!relative_path || relative_path.trim() == '') return false
14471461
if (this._user_allow_patterns.ignores(relative_path)) {
14481462
return false
14491463
}

0 commit comments

Comments
 (0)