Skip to content

Commit 08f8981

Browse files
authored
fix: don’t try to chmod unlinked files (npm#80)
`linkGently` would return true if a link target had been visited before. `linkBin` would then chmod the link `to`, regardless of whether this file exists. This causes `npm install` to fail if multiple packages link to a non-existent bin with the same name. By returning false in `linkGently`, `linkBin` no skips the chmod on the non-existent file. ## References Fixes npm#4597
1 parent f24eddb commit 08f8981

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

lib/link-gently.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const CLOBBER = Symbol('clobber - ours or in forceful mode')
2828

2929
const linkGently = async ({ path, to, from, absFrom, force }) => {
3030
if (seen.has(to)) {
31-
return true
31+
return false
3232
}
3333
seen.add(to)
3434

test/link-gently.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ t.test('racey race', async t => {
109109
existingLink: t.fixture('symlink', './pkg/hello.js'),
110110
existingFile: 'hello',
111111
})
112-
await Promise.all([
112+
const multipleLinked = await Promise.all([
113113
mockedLinkGently({
114114
path: `${dir}/pkg`,
115115
from: `./pkg/hello.js`,
@@ -126,6 +126,8 @@ t.test('racey race', async t => {
126126
}),
127127
new Promise((res) => fs.symlink(__filename, `${dir}/racecar`, 'file', res)),
128128
])
129+
t.ok(multipleLinked[0] || multipleLinked[1], 'should link one path succesfully')
130+
t.notSame(multipleLinked[0], multipleLinked[1], 'should fail to link the other path')
129131
const target = fs.readlinkSync(`${dir}/racecar`)
130132
t.match(target, /^\.\/(other)?pkg\/hello\.js$/, 'should link to one of them')
131133
})

0 commit comments

Comments
 (0)