mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-21 21:01:06 -05:00
Add 10s timeout to recursive list files
This commit is contained in:
@@ -107,34 +107,34 @@ export async function listFiles(dirPath: string, recursive: boolean): Promise<st
|
|||||||
// globby doesnt natively support top down level by level globbing, so we implement it ourselves
|
// globby doesnt natively support top down level by level globbing, so we implement it ourselves
|
||||||
async function globbyLevelByLevel(options?: Options) {
|
async function globbyLevelByLevel(options?: Options) {
|
||||||
let results: string[] = []
|
let results: string[] = []
|
||||||
|
const globbingProcess = async () => {
|
||||||
let currentLevel = 0
|
let currentLevel = 0
|
||||||
while (results.length < LIST_FILES_LIMIT) {
|
while (results.length < LIST_FILES_LIMIT) {
|
||||||
// Construct the glob pattern for the current level
|
|
||||||
const pattern = currentLevel === 0 ? "*" : `${"*/".repeat(currentLevel)}*`
|
const pattern = currentLevel === 0 ? "*" : `${"*/".repeat(currentLevel)}*`
|
||||||
|
|
||||||
// Get files and directories at the current level
|
|
||||||
const filesAtLevel = await globby(pattern, options)
|
const filesAtLevel = await globby(pattern, options)
|
||||||
|
|
||||||
// If no more files found at this level, break the loop
|
|
||||||
if (filesAtLevel.length === 0) {
|
if (filesAtLevel.length === 0) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the files found at this level to the result
|
|
||||||
results.push(...filesAtLevel)
|
results.push(...filesAtLevel)
|
||||||
|
|
||||||
// If we have reached the max limit, slice the array to the limit and break
|
|
||||||
if (results.length >= LIST_FILES_LIMIT) {
|
if (results.length >= LIST_FILES_LIMIT) {
|
||||||
results = results.slice(0, LIST_FILES_LIMIT)
|
results = results.slice(0, LIST_FILES_LIMIT)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move to the next level
|
|
||||||
currentLevel++
|
currentLevel++
|
||||||
}
|
}
|
||||||
|
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
// Timeout after 10 seconds and return partial results
|
||||||
|
const timeoutPromise = new Promise<string[]>((_, reject) => {
|
||||||
|
setTimeout(() => reject(new Error("Globbing timeout")), 10_000)
|
||||||
|
})
|
||||||
|
try {
|
||||||
|
return await Promise.race([globbingProcess(), timeoutPromise])
|
||||||
|
} catch (error) {
|
||||||
|
console.warn("Globbing timed out, returning partial results")
|
||||||
|
return results
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function separateFiles(allFiles: string[]): { filesToParse: string[]; remainingFiles: string[] } {
|
function separateFiles(allFiles: string[]): { filesToParse: string[]; remainingFiles: string[] } {
|
||||||
const extensions = [
|
const extensions = [
|
||||||
|
|||||||
Reference in New Issue
Block a user