Skip to content

Commit

Permalink
refactor: check for ENOENT in safeLink instead of doing a stat
Browse files Browse the repository at this point in the history
  • Loading branch information
andreypopp authored and zkochan committed Jan 16, 2017
1 parent d5f6b09 commit 48e5a1d
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/fs/hardlinkDir.ts
Expand Up @@ -12,10 +12,6 @@ export default async function hardlinkDir(existingDir: string, newDir: string) {
const newPath = path.join(newDir, relativePath)
const stat = await fs.lstat(existingPath)
if (stat.isSymbolicLink()) {
// filter out broken symlinks
if (!await fs.exists(existingPath)) {
return;
}
return safeLink(existingPath, newPath)
}
if (stat.isDirectory()) {
Expand All @@ -32,8 +28,9 @@ async function safeLink(existingPath: string, newPath: string) {
try {
await fs.link(existingPath, newPath)
} catch (err) {
// shouldn't normally happen, but if the file was already somehow linked,
// EEXIST: shouldn't normally happen, but if the file was already somehow linked,
// the installation should not fail
if (err.code !== 'EEXIST') throw err
// ENOENT: might happen if package contains a broken symlink
if (err.code !== 'EEXIST' && err.code !== 'ENOENT') throw err
}
}

0 comments on commit 48e5a1d

Please sign in to comment.