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

21
lib/analysis-paths.js generated
View file

@ -1,5 +1,13 @@
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const path = __importStar(require("path"));
function isInterpretedLanguage(language) {
return language === "javascript" || language === "python";
}
@ -24,7 +32,7 @@ function printPathFiltersWarning(config, logger) {
}
}
exports.printPathFiltersWarning = printPathFiltersWarning;
function includeAndExcludeAnalysisPaths(config) {
function includeAndExcludeAnalysisPaths(config, 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
@ -35,8 +43,15 @@ function includeAndExcludeAnalysisPaths(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
// extracted or ignored. It does not control which directories are traversed.