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

Function sortFileMatchesByModifiedTime

src/utils/glob.ts:105–134  ·  view source on GitHub ↗
(
  paths: string[],
  abortSignal: AbortSignal,
)

Source from the content-addressed store, hash-verified

103}
104
105async function sortFileMatchesByModifiedTime(
106 paths: string[],
107 abortSignal: AbortSignal,
108): Promise<string[]> {
109 const fs = getFsImplementation()
110 const matches: Array<{ path: string; mtimeMs: number }> = []
111 const batchSize = 256
112
113 for (let i = 0; i < paths.length; i += batchSize) {
114 if (abortSignal.aborted) {
115 throw abortSignal.reason ?? new Error('Glob aborted')
116 }
117
118 const batch = paths.slice(i, i + batchSize)
119 const stats = await Promise.allSettled(batch.map(path => fs.stat(path)))
120 for (let j = 0; j < batch.length; j++) {
121 const result = stats[j]!
122 matches.push({
123 path: batch[j]!,
124 mtimeMs:
125 result.status === 'fulfilled' ? (result.value.mtimeMs ?? 0) : 0,
126 })
127 }
128 }
129
130 matches.sort(
131 (a, b) => a.mtimeMs - b.mtimeMs || a.path.localeCompare(b.path),
132 )
133 return matches.map(match => match.path)
134}
135
136function getDirectoryGlobMaxDepth(pattern: string): number {
137 const normalized = normalizeGlobPattern(pattern).replace(/\/+$/, '')

Callers 1

globFunction · 0.85

Calls 1

getFsImplementationFunction · 0.85

Tested by

no test coverage detected