Skip to content

Commit 8c3b143

Browse files
authored
fix(arborist): shrinkwrap throws when trying to read a folder without permissions (#4258)
* fix(arborist): shrinkwrap throws trying to read a folder without permissions Fix an issue where shrinkwrap throws an error when trying to read a folder that it doesn't have permissions to, instead of returning a correct object with an error
1 parent fabcf43 commit 8c3b143

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

workspaces/arborist/lib/shrinkwrap.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,13 @@ class Shrinkwrap {
476476
// all good! hidden lockfile is the newest thing in here.
477477
return data
478478
}).catch(er => {
479-
const rel = relpath(this.path, this.filename)
480-
this.log.verbose('shrinkwrap', `failed to load ${rel}`, er)
479+
/* istanbul ignore else */
480+
if (typeof this.filename === 'string') {
481+
const rel = relpath(this.path, this.filename)
482+
this.log.verbose('shrinkwrap', `failed to load ${rel}`, er)
483+
} else {
484+
this.log.verbose('shrinkwrap', `failed to load ${this.path}`, er)
485+
}
481486
this.loadingError = er
482487
this.loadedFromDisk = false
483488
this.ancientLockfile = false

workspaces/arborist/test/shrinkwrap.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,4 +1597,19 @@ t.test('setting lockfileVersion from the file contents', async t => {
15971597
})
15981598

15991599
t.equal(Shrinkwrap.defaultLockfileVersion, 2, 'default is 2')
1600+
1601+
t.test('load should return error correctly when it cant access folder',
1602+
{ skip: process.platform === 'win32' ? 'skip chmod in windows' : false },
1603+
async t => {
1604+
const dir = t.testdir({})
1605+
try {
1606+
fs.chmodSync(dir, '000')
1607+
const res = await Shrinkwrap.load({ path: dir })
1608+
t.ok(res.loadingError, 'loading error should exist')
1609+
t.strictSame(res.loadingError.errno, -13)
1610+
t.strictSame(res.loadingError.code, 'EACCES')
1611+
} finally {
1612+
fs.chmodSync(dir, '666')
1613+
}
1614+
})
16001615
})

0 commit comments

Comments
 (0)