Files
pnpm/store/cafs/src/writeFile.ts
T
Luis HebendanzandZoltan Kochan 9b9faa5c24 fix: retry filesystem operations on EAGAIN (#9959)
* fix: retry filesystem operations on EAGAIN

filesystem operations can raise EAGAIN to tell the application to try
again later. This is especially often the case under ZFS.

fix: move wrapped functions to graceful-fs directly

* fix: retry filesystem operations on EAGAIN

* fix: retry filesystem operations on EAGAIN

* fix: indexed-pkg-importer

* test: fix

* docs: add changeset

---------

Co-authored-by: Zoltan Kochan <z@kochan.io>
2025-09-29 09:32:43 +02:00

22 lines
432 B
TypeScript

import path from 'path'
import fs from '@pnpm/graceful-fs'
const dirs = new Set()
export function writeFile (
fileDest: string,
buffer: Buffer,
mode?: number
): void {
makeDirForFile(fileDest)
fs.writeFileSync(fileDest, buffer, { mode })
}
function makeDirForFile (fileDest: string): void {
const dir = path.dirname(fileDest)
if (!dirs.has(dir)) {
fs.mkdirSync(dir, { recursive: true })
dirs.add(dir)
}
}