1
0
Fork 0

glob: skip error when subdirectory have not permission

pull/1015/head
howyi 2022-03-10 20:19:37 +09:00
parent a502af8759
commit 8509874125
2 changed files with 37 additions and 6 deletions

View File

@ -114,6 +114,30 @@ describe('globber', () => {
])
})
it('skip permission denied directory', async () => {
// Create the following layout:
// <root>
// <root>/file
// <root>/folder-a <- EACCESS
// <root>/folder-a/file
// <root>/folder-b
// <root>/folder-b/file
const root = path.join(getTestTemp(), 'skip-permission-denied-directory')
await fs.mkdir(path.join(root, 'folder-a'), {recursive: true})
await fs.writeFile(path.join(root, 'folder-a', 'file'), 'test file content')
await fs.chmod(path.join(root, 'folder-a'), '000')
await fs.mkdir(path.join(root, 'folder-b'), {recursive: true})
await fs.writeFile(path.join(root, 'folder-b', 'file'), 'test file content')
await fs.writeFile(path.join(root, 'file'), 'test file content')
const itemPaths = await glob(`${root}/**/file`, {})
await fs.chmod(path.join(root, 'folder-a'), '777')
expect(itemPaths).toEqual([
path.join(root, 'file'),
path.join(root, 'folder-b', 'file')
])
})
it('does not match file with trailing slash when implicitDescendants=true', async () => {
// Create the following layout:
// <root>

View File

@ -139,12 +139,19 @@ export class DefaultGlobber implements Globber {
continue
}
try {
// Push the child items in reverse
const childLevel = item.level + 1
const childItems = (await fs.promises.readdir(item.path)).map(
x => new SearchState(path.join(item.path, x), childLevel)
)
stack.push(...childItems.reverse())
} catch (err) {
if (err.code === 'EACCES') {
continue
}
throw err
}
}
// File
else if (match & MatchKind.File) {