Attempt to clean up the database cluster directory
This will help to avoid issues where the database cluster directory is left in an inconsistent state.
This commit is contained in:
parent
81b81437fd
commit
1354fe5355
13 changed files with 288 additions and 8 deletions
39
lib/init.js
generated
39
lib/init.js
generated
|
|
@ -23,17 +23,19 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isSipEnabled = exports.checkInstallPython311 = exports.printPathFiltersWarning = exports.runInit = exports.initConfig = exports.initCodeQL = void 0;
|
||||
exports.cleanupDatabaseClusterDirectory = exports.isSipEnabled = exports.checkInstallPython311 = exports.printPathFiltersWarning = exports.runInit = exports.initConfig = exports.initCodeQL = void 0;
|
||||
const fs = __importStar(require("fs"));
|
||||
const path = __importStar(require("path"));
|
||||
const exec = __importStar(require("@actions/exec/lib/exec"));
|
||||
const toolrunner = __importStar(require("@actions/exec/lib/toolrunner"));
|
||||
const safeWhich = __importStar(require("@chrisgavin/safe-which"));
|
||||
const actions_util_1 = require("./actions-util");
|
||||
const codeql_1 = require("./codeql");
|
||||
const configUtils = __importStar(require("./config-utils"));
|
||||
const languages_1 = require("./languages");
|
||||
const tools_features_1 = require("./tools-features");
|
||||
const tracer_config_1 = require("./tracer-config");
|
||||
const util = __importStar(require("./util"));
|
||||
async function initCodeQL(toolsInput, apiDetails, tempDir, variant, defaultCliVersion, logger) {
|
||||
logger.startGroup("Setup CodeQL tools");
|
||||
const { codeql, toolsDownloadDurationMs, toolsSource, toolsVersion } = await (0, codeql_1.setupCodeQL)(toolsInput, apiDetails, tempDir, variant, defaultCliVersion, logger, true);
|
||||
|
|
@ -111,4 +113,39 @@ async function isSipEnabled(logger) {
|
|||
}
|
||||
}
|
||||
exports.isSipEnabled = isSipEnabled;
|
||||
function cleanupDatabaseClusterDirectory(config, logger,
|
||||
// We can't stub the fs module in tests, so we allow the caller to override the rmSync function
|
||||
// for testing.
|
||||
rmSync = fs.rmSync) {
|
||||
if (fs.existsSync(config.dbLocation) &&
|
||||
(fs.statSync(config.dbLocation).isFile() ||
|
||||
fs.readdirSync(config.dbLocation).length)) {
|
||||
logger.warning(`The database cluster directory ${config.dbLocation} must be empty. Attempting to clean it up.`);
|
||||
try {
|
||||
rmSync(config.dbLocation, {
|
||||
force: true,
|
||||
maxRetries: 3,
|
||||
recursive: true,
|
||||
});
|
||||
logger.info(`Cleaned up database cluster directory ${config.dbLocation}.`);
|
||||
}
|
||||
catch (e) {
|
||||
const blurb = `The CodeQL Action requires an empty database cluster directory. ${(0, actions_util_1.getOptionalInput)("db-location")
|
||||
? `This is currently configured to be ${config.dbLocation}. `
|
||||
: `By default, this is located at ${config.dbLocation}. ` +
|
||||
"You can customize it using the 'db-location' input to the init Action. "}An attempt was made to clean up the directory, but this failed.`;
|
||||
// Hosted runners are automatically cleaned up, so this error should not occur for hosted runners.
|
||||
if ((0, actions_util_1.isSelfHostedRunner)()) {
|
||||
throw new util.ConfigurationError(`${blurb} This can happen if another process is using the directory or the directory is owned by a different user. ` +
|
||||
"Please clean up the directory manually and rerun the job.");
|
||||
}
|
||||
else {
|
||||
throw new Error(`${blurb} This shouldn't typically happen on hosted runners. ` +
|
||||
"If you are using an advanced setup, please check your workflow, otherwise we " +
|
||||
"recommend rerunning the job.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.cleanupDatabaseClusterDirectory = cleanupDatabaseClusterDirectory;
|
||||
//# sourceMappingURL=init.js.map
|
||||
Loading…
Add table
Add a link
Reference in a new issue