MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / collectFilesForZip

Function collectFilesForZip

source code/utils/plugins/zipCache.ts:237–325  ·  view source on GitHub ↗

* Recursively collect files from a directory for zipping. * Uses lstat to detect symlinks and tracks visited inodes for cycle detection.

(
  baseDir: string,
  relativePath: string,
  files: Record<string, ZipEntry>,
  visited: Set<string>,
)

Source from the content-addressed store, hash-verified

235 * Uses lstat to detect symlinks and tracks visited inodes for cycle detection.
236 */
237async function collectFilesForZip(
238 baseDir: string,
239 relativePath: string,
240 files: Record<string, ZipEntry>,
241 visited: Set<string>,
242): Promise<void> {
243 const currentDir = relativePath ? join(baseDir, relativePath) : baseDir
244 let entries: string[]
245 try {
246 entries = await readdir(currentDir)
247 } catch {
248 return
249 }
250
251 // Track visited directories by dev+ino to detect symlink cycles.
252 // bigint: true is required — on Windows NTFS, the file index packs a 16-bit
253 // sequence number into the high bits. Once that sequence exceeds ~32 (very
254 // common on a busy CI runner that churns through temp files), the value
255 // exceeds Number.MAX_SAFE_INTEGER and two adjacent directories round to the
256 // same JS number, causing subdirs to be silently skipped as "cycles". This
257 // broke the round-trip test on Windows CI when sharding shuffled which tests
258 // ran first and pushed MFT sequence numbers over the precision cliff.
259 // See also: markdownConfigLoader.ts getFileIdentity, anthropics/claude-code#13893
260 try {
261 const dirStat = await stat(currentDir, { bigint: true })
262 // ReFS (Dev Drive), NFS, some FUSE mounts report dev=0 and ino=0 for
263 // everything. Fail open: skip cycle detection rather than skip the
264 // directory. We already skip symlinked directories unconditionally below,
265 // so the only cycle left here is a bind mount, which we accept.
266 if (dirStat.dev !== 0n || dirStat.ino !== 0n) {
267 const key = `${dirStat.dev}:${dirStat.ino}`
268 if (visited.has(key)) {
269 logForDebugging(`Skipping symlink cycle at ${currentDir}`)
270 return
271 }
272 visited.add(key)
273 }
274 } catch {
275 return
276 }
277
278 for (const entry of entries) {
279 // Skip hidden files that are git-related
280 if (entry === '.git') {
281 continue
282 }
283
284 const fullPath = join(currentDir, entry)
285 const relPath = relativePath ? `${relativePath}/${entry}` : entry
286
287 let fileStat
288 try {
289 fileStat = await lstat(fullPath)
290 } catch {
291 continue
292 }
293
294 // Skip symlinked directories (follow symlinked files)

Callers 1

createZipFromDirectoryFunction · 0.85

Calls 6

readdirFunction · 0.85
statFunction · 0.85
logForDebuggingFunction · 0.85
readFileFunction · 0.85
hasMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected