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

Function extractZipToDirectory

source code/utils/plugins/zipCache.ts:333–366  ·  view source on GitHub ↗
(
  zipPath: string,
  targetDir: string,
)

Source from the content-addressed store, hash-verified

331 * @param targetDir - Directory to extract into
332 */
333export async function extractZipToDirectory(
334 zipPath: string,
335 targetDir: string,
336): Promise<void> {
337 const zipBuf = await getFsImplementation().readFileBytes(zipPath)
338 const files = await unzipFile(zipBuf)
339 // fflate doesn't surface external_attr — parse the central directory so
340 // exec bits survive extraction (hooks/scripts need +x to run via `sh -c`).
341 const modes = parseZipModes(zipBuf)
342
343 await getFsImplementation().mkdir(targetDir)
344
345 for (const [relPath, data] of Object.entries(files)) {
346 // Skip directory entries (trailing slash)
347 if (relPath.endsWith('/')) {
348 await getFsImplementation().mkdir(join(targetDir, relPath))
349 continue
350 }
351
352 const fullPath = join(targetDir, relPath)
353 await getFsImplementation().mkdir(dirname(fullPath))
354 await writeFile(fullPath, data)
355 const mode = modes[relPath]
356 if (mode && mode & 0o111) {
357 // Swallow EPERM/ENOTSUP (NFS root_squash, some FUSE mounts) — losing +x
358 // is the pre-PR behavior and better than aborting mid-extraction.
359 await chmod(fullPath, mode & 0o777).catch(() => {})
360 }
361 }
362
363 logForDebugging(
364 `Extracted ZIP to ${targetDir}: ${Object.keys(files).length} entries`,
365 )
366}
367
368/**
369 * Convert a plugin directory to a ZIP in-place: zip → atomic write → delete dir.

Calls 6

getFsImplementationFunction · 0.85
unzipFileFunction · 0.85
parseZipModesFunction · 0.85
logForDebuggingFunction · 0.85
entriesMethod · 0.80
keysMethod · 0.80

Tested by

no test coverage detected