mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-23 23:29:17 -05:00
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:
6
.changeset/cute-cars-mix.md
Normal file
6
.changeset/cute-cars-mix.md
Normal 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).
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user