skip symlinks to directories when generating plugin manifest (#30721)

This commit is contained in:
Dan Cech
2021-01-29 08:51:37 -05:00
committed by GitHub
parent 52a8f2bf7e
commit 06061c8741

View File

@ -13,7 +13,7 @@ async function* walk(dir: string, baseDir: string): AsyncGenerator<string, any,
} else if (d.isFile()) { } else if (d.isFile()) {
yield path.posix.relative(baseDir, entry); yield path.posix.relative(baseDir, entry);
} else if (d.isSymbolicLink()) { } else if (d.isSymbolicLink()) {
const realPath = fs.realpathSync(entry); const realPath = await (fs.promises as any).realpath(entry);
if (!realPath.startsWith(baseDir)) { if (!realPath.startsWith(baseDir)) {
throw new Error( throw new Error(
`symbolic link ${path.posix.relative( `symbolic link ${path.posix.relative(
@ -22,10 +22,14 @@ async function* walk(dir: string, baseDir: string): AsyncGenerator<string, any,
)} targets a file outside of the base directory: ${baseDir}` )} targets a file outside of the base directory: ${baseDir}`
); );
} }
// if resolved symlink target is a file include it in the manifest
const stats = await (fs.promises as any).stat(realPath);
if (stats.isFile()) {
yield path.posix.relative(baseDir, entry); yield path.posix.relative(baseDir, entry);
} }
} }
} }
}
export async function buildManifest(dir: string): Promise<ManifestInfo> { export async function buildManifest(dir: string): Promise<ManifestInfo> {
const pluginJson = JSON.parse(fs.readFileSync(path.join(dir, 'plugin.json'), { encoding: 'utf8' })); const pluginJson = JSON.parse(fs.readFileSync(path.join(dir, 'plugin.json'), { encoding: 'utf8' }));