Skip to content

Commit

Permalink
fix: fall back to copying if linking fails
Browse files Browse the repository at this point in the history
  • Loading branch information
zkochan committed Jun 1, 2020
1 parent eb82084 commit 429c5a5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/soft-insects-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pnpm/package-store": patch
---

If creating a hard-link to a file from the store fails, fall back to copying the file.
15 changes: 12 additions & 3 deletions packages/package-store/src/storeController/createImportPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import fs = require('mz/fs')
import pLimit from 'p-limit'
import path = require('path')
import exists = require('path-exists')
import pathTemp = require('path-temp')
import renameOverwrite = require('rename-overwrite')
import importIndexedDir from '../fs/importIndexedDir'

const limitLinking = pLimit(16)
Expand Down Expand Up @@ -112,7 +110,18 @@ async function hardlinkPkg (

if (!opts.fromStore || opts.force || !await exists(pkgJsonPath) || !await pkgLinkedToStore(pkgJsonPath, opts.filesMap['package.json'], to)) {
importingLogger.debug({ to, method: 'hardlink' })
await importIndexedDir(fs.link, to, opts.filesMap)
await importIndexedDir(linkOrCopy, to, opts.filesMap)
}
}

async function linkOrCopy (existingPath: string, newPath: string) {
try {
await fs.link(existingPath, newPath)
} catch (err) {
// In some VERY rare cases (1 in a thousand), hard-link creation fails on Windows.
// In that case, we just fall back to copying.
// This issue is reproducible with "pnpm add @material-ui/icons@4.9.1"
await fs.copyFile(existingPath, newPath)
}
}

Expand Down

0 comments on commit 429c5a5

Please sign in to comment.