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

(cherry picked from commit 06061c8741)

Co-authored-by: Dan Cech <dcech@grafana.com>
This commit is contained in:
Grot (@grafanabot)
2021-01-29 13:43:57 -08:00
committed by GitHub
co-authored by Dan Cech
parent 563e98d334
commit b78166f8df
@@ -13,7 +13,7 @@ async function* walk(dir: string, baseDir: string): AsyncGenerator<string, any,
} else if (d.isFile()) {
yield path.posix.relative(baseDir, entry);
} else if (d.isSymbolicLink()) {
const realPath = fs.realpathSync(entry);
const realPath = await (fs.promises as any).realpath(entry);
if (!realPath.startsWith(baseDir)) {
throw new Error(
`symbolic link ${path.posix.relative(
@@ -22,7 +22,11 @@ async function* walk(dir: string, baseDir: string): AsyncGenerator<string, any,
)} targets a file outside of the base directory: ${baseDir}`
);
}
yield path.posix.relative(baseDir, entry);
// 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);
}
}
}
}