fix(fs.hard-link-dir): don't try to hard link a directory to itself

This commit is contained in:
Zoltan Kochan
2023-01-17 03:36:31 +02:00
parent 4655dd41e1
commit 00d86db161
2 changed files with 8 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/fs.hard-link-dir": patch
---
Don't try to hard link the source directory to itself.

View File

@@ -2,6 +2,9 @@ import path from 'path'
import { promises as fs } from 'fs'
export async function hardLinkDir (src: string, destDirs: string[]) {
if (destDirs.length === 0) return
// Don't try to hard link the source directory to itself
destDirs = destDirs.filter((destDir) => path.relative(destDir, src) !== '')
const files = await fs.readdir(src)
await Promise.all(
files.map(async (file) => {