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

Function atomicWriteToZipCache

source code/utils/plugins/zipCache.ts:177–203  ·  view source on GitHub ↗
(
  targetPath: string,
  data: string | Uint8Array,
)

Source from the content-addressed store, hash-verified

175 * Writes to a temp file in the same directory, then renames.
176 */
177export async function atomicWriteToZipCache(
178 targetPath: string,
179 data: string | Uint8Array,
180): Promise<void> {
181 const dir = dirname(targetPath)
182 await getFsImplementation().mkdir(dir)
183
184 const tmpName = `.${basename(targetPath)}.tmp.${randomBytes(4).toString('hex')}`
185 const tmpPath = join(dir, tmpName)
186
187 try {
188 if (typeof data === 'string') {
189 await writeFile(tmpPath, data, { encoding: 'utf-8' })
190 } else {
191 await writeFile(tmpPath, data)
192 }
193 await rename(tmpPath, targetPath)
194 } catch (error) {
195 // Clean up tmp file on failure
196 try {
197 await rm(tmpPath, { force: true })
198 } catch {
199 // ignore cleanup errors
200 }
201 throw error
202 }
203}
204
205// fflate's ZippableFile tuple form: [data, opts]. Using the tuple lets us
206// store {os, attrs} so parseZipModes can recover exec bits on extraction.

Calls 4

getFsImplementationFunction · 0.85
renameFunction · 0.85
rmFunction · 0.85
toStringMethod · 0.65

Tested by

no test coverage detected