Skip to content

Commit

Permalink
fix: don’t try to chmod unlinked files (#80)
Browse files Browse the repository at this point in the history
`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/cli#4597
  • Loading branch information
remcohaszing committed Jul 11, 2023
1 parent f24eddb commit 08f8981
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/link-gently.js
Expand Up @@ -28,7 +28,7 @@ const CLOBBER = Symbol('clobber - ours or in forceful mode')

const linkGently = async ({ path, to, from, absFrom, force }) => {
if (seen.has(to)) {
return true
return false
}
seen.add(to)

Expand Down
4 changes: 3 additions & 1 deletion test/link-gently.js
Expand Up @@ -109,7 +109,7 @@ t.test('racey race', async t => {
existingLink: t.fixture('symlink', './pkg/hello.js'),
existingFile: 'hello',
})
await Promise.all([
const multipleLinked = await Promise.all([
mockedLinkGently({
path: `${dir}/pkg`,
from: `./pkg/hello.js`,
Expand All @@ -126,6 +126,8 @@ t.test('racey race', async t => {
}),
new Promise((res) => fs.symlink(__filename, `${dir}/racecar`, 'file', res)),
])
t.ok(multipleLinked[0] || multipleLinked[1], 'should link one path succesfully')
t.notSame(multipleLinked[0], multipleLinked[1], 'should fail to link the other path')
const target = fs.readlinkSync(`${dir}/racecar`)
t.match(target, /^\.\/(other)?pkg\/hello\.js$/, 'should link to one of them')
})

0 comments on commit 08f8981

Please sign in to comment.