mirror of
https://github.com/pnpm/pnpm.git
synced 2026-01-09 07:28:37 -05:00
fix(fs.hard-link-dir): ignore broken symlinks
This commit is contained in:
5
.changeset/dry-years-sort.md
Normal file
5
.changeset/dry-years-sort.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/fs.hard-link-dir": patch
|
||||
---
|
||||
|
||||
Ignore broken symlinks.
|
||||
@@ -29,16 +29,13 @@ export async function hardLinkDir (src: string, destDirs: string[]) {
|
||||
destDirs.map(async (destDir) => {
|
||||
const destFile = path.join(destDir, file)
|
||||
try {
|
||||
await linkOrCopy(srcFile, destFile)
|
||||
await linkOrCopyFile(srcFile, destFile)
|
||||
} catch (err: any) { // eslint-disable-line
|
||||
if (err.code === 'ENOENT') {
|
||||
await fs.mkdir(destDir, { recursive: true })
|
||||
await linkOrCopy(srcFile, destFile)
|
||||
// Ignore broken symlinks
|
||||
return
|
||||
}
|
||||
if (err.code !== 'EEXIST') {
|
||||
throw err
|
||||
}
|
||||
throw err
|
||||
}
|
||||
})
|
||||
)
|
||||
@@ -46,6 +43,21 @@ export async function hardLinkDir (src: string, destDirs: string[]) {
|
||||
)
|
||||
}
|
||||
|
||||
async function linkOrCopyFile (srcFile: string, destFile: string) {
|
||||
try {
|
||||
await linkOrCopy(srcFile, destFile)
|
||||
} catch (err: any) { // eslint-disable-line
|
||||
if (err.code === 'ENOENT') {
|
||||
await fs.mkdir(path.dirname(destFile), { recursive: true })
|
||||
await linkOrCopy(srcFile, destFile)
|
||||
return
|
||||
}
|
||||
if (err.code !== 'EEXIST') {
|
||||
throw err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This function could be optimized because we don't really need to try linking again
|
||||
* if linking failed once.
|
||||
|
||||
Reference in New Issue
Block a user