Exclude the temporary directory from scanning.

This commit is contained in:
Chris Gavin 2020-09-28 12:15:06 +01:00
parent 2841489ddf
commit 206e34cbb4
No known key found for this signature in database
GPG key ID: 07F950B80C27E4DA
9 changed files with 85 additions and 16 deletions

View file

@ -1,3 +1,4 @@
import * as path from "path";
import * as configUtils from "./config-utils";
import { Logger } from "./logging";
@ -37,7 +38,10 @@ export function printPathFiltersWarning(
}
}
export function includeAndExcludeAnalysisPaths(config: configUtils.Config) {
export function includeAndExcludeAnalysisPaths(
config: configUtils.Config,
logger: Logger
) {
// The 'LGTM_INDEX_INCLUDE' and 'LGTM_INDEX_EXCLUDE' environment variables
// control which files/directories are traversed when scanning.
// This allows including files that otherwise would not be scanned, or
@ -48,10 +52,17 @@ export function includeAndExcludeAnalysisPaths(config: configUtils.Config) {
if (config.paths.length !== 0) {
process.env["LGTM_INDEX_INCLUDE"] = buildIncludeExcludeEnvVar(config.paths);
}
if (config.pathsIgnore.length !== 0) {
process.env["LGTM_INDEX_EXCLUDE"] = buildIncludeExcludeEnvVar(
config.pathsIgnore
// If the temporary directory is in the working directory ignore that too.
const tempRelativeToWorking = path.relative(process.cwd(), config.tempDir);
let pathsIgnore = config.pathsIgnore;
if (!tempRelativeToWorking.startsWith("..")) {
logger.warning(
"Storing the CodeQL Runner in the directory being analyzed is not recommended."
);
pathsIgnore = pathsIgnore.concat(config.tempDir);
}
if (pathsIgnore.length !== 0) {
process.env["LGTM_INDEX_EXCLUDE"] = buildIncludeExcludeEnvVar(pathsIgnore);
}
// The 'LGTM_INDEX_FILTERS' environment variable controls which files are