Skip to content

Commit bc3f568

Browse files
author
Justin Skywork
committed
fix: handle EPERM on chmod during atomic writes for Windows/Docker #53947
1 parent 398d58f commit bc3f568

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/shared/fs-atomic-fix.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import fs from "fs";
2+
3+
/**
4+
* Handles EPERM issues during chmod on Windows-mounted Docker volumes.
5+
* Addresses #53947.
6+
*/
7+
export function writeTextFileAtomicSync(pathname: string, value: string, mode: number = 0o600) {
8+
const tempPath = `${pathname}.tmp-${process.pid}-${Date.now()}`;
9+
fs.writeFileSync(tempPath, value, "utf8");
10+
11+
try {
12+
// This fails on Windows-mounted volumes in Docker
13+
fs.chmodSync(tempPath, mode);
14+
} catch (e) {
15+
// Silently continue if chmod fails (EPERM expected on NTFS/CIFS mounts)
16+
}
17+
18+
fs.renameSync(tempPath, pathname);
19+
}

0 commit comments

Comments
 (0)