fix: handle ENOENT errors in containerized environments by falling back to copy (#10218)

* fix: linkOrCopy failed

* refactor: hard-link-dir

* docs: add changesets

---------

Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
Kairui Liu
2025-11-22 23:27:15 +08:00
committed by GitHub
parent 144ce0e98b
commit 2a50b8936e
2 changed files with 13 additions and 2 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/fs.hard-link-dir": patch
"pnpm": patch
---
Handle ENOENT errors thrown by `fs.linkSync()`, which can occur in containerized environments (OverlayFS) instead of EXDEV. The operation now gracefully falls back to `fs.copyFileSync()` in these cases [#10217](https://github.com/pnpm/pnpm/issues/10217).

View File

@@ -92,7 +92,12 @@ function linkOrCopy (srcFile: string, destFile: string): void {
try {
gfs.linkSync(srcFile, destFile)
} catch (err: unknown) {
if (!(util.types.isNativeError(err) && 'code' in err && err.code === 'EXDEV')) throw err
gfs.copyFileSync(srcFile, destFile)
// In some container environments (OverlayFS), linkSync throws ENOENT
// instead of EXDEV when linking across layers. We must fallback to copy in this case too.
if (util.types.isNativeError(err) && 'code' in err && (err.code === 'EXDEV' || err.code === 'ENOENT')) {
gfs.copyFileSync(srcFile, destFile)
} else {
throw err
}
}
}