MCPcopy Create free account
hub / github.com/Noumena-Network/code / scan

Function scan

src/utils/glob.ts:210–243  ·  view source on GitHub ↗
(currentDir: string, relativeDir = '')

Source from the content-addressed store, hash-verified

208 }
209
210 async function scan(currentDir: string, relativeDir = ''): Promise<void> {
211 if (abortSignal.aborted) {
212 throw abortSignal.reason ?? new Error('Glob aborted')
213 }
214
215 const entries = await fs.readdir(currentDir)
216 await Promise.all(
217 entries.map(async entry => {
218 if (!entry.isDirectory()) {
219 return
220 }
221
222 const absolutePath = join(currentDir, entry.name)
223 const relativePath = relativeDir
224 ? `${relativeDir}/${entry.name}`
225 : entry.name
226 const relativePathWithSlash = `${relativePath}/`
227
228 if (shouldIgnore(relativePath) || shouldIgnore(relativePathWithSlash)) {
229 return
230 }
231
232 if (matcher(relativePathWithSlash)) {
233 const stats = await fs.stat(absolutePath)
234 matches.push({ path: absolutePath, mtimeMs: stats.mtimeMs })
235 }
236
237 const depth = relativePath.split('/').filter(Boolean).length
238 if (depth < maxDepth) {
239 await scan(absolutePath, relativePath)
240 }
241 }),
242 )
243 }
244
245 await scan(searchDir)
246

Callers 1

globDirectoriesFunction · 0.70

Calls 1

shouldIgnoreFunction · 0.85

Tested by

no test coverage detected