Don’t try reading from pipes or special file descriptors (#19421)

Fixes #19420
This commit is contained in:
Jordan Pittman
2025-12-08 17:04:51 -05:00
committed by GitHub
parent 74b58324bc
commit f785edf239
2 changed files with 14 additions and 4 deletions
@@ -13,10 +13,19 @@ export function drainStdin() {
}
export async function outputFile(file: string, contents: string) {
try {
let currentContents = await fs.readFile(file, 'utf8')
if (currentContents === contents) return // Skip writing the file
} catch {}
// Check for special files like `/dev/stdout` or pipes. We don't want to read from these as that
// will hang the process until the file descriptors are closed.
let isSpecialFile = await fs
.stat(file)
.then((stats) => stats.isCharacterDevice() || stats.isFIFO())
.catch(() => false)
if (!isSpecialFile) {
try {
let currentContents = await fs.readFile(file, 'utf8')
if (currentContents === contents) return // Skip writing the file
} catch {}
}
// Ensure the parent directories exist
await fs.mkdir(path.dirname(file), { recursive: true })