Remove rmDir references

`rmDir` is not available on the node version used by the actions runner.

Instead, use the `del` package. It is safe, well-tested, and
cross-platform.
This commit is contained in:
Andrew Eisenberg 2021-12-08 12:00:54 -08:00
parent cbed0358c6
commit 45dc27d3c1
75 changed files with 8130 additions and 28809 deletions

View file

@ -3,6 +3,7 @@ import * as os from "os";
import * as path from "path";
import { Command } from "commander";
import del from "del";
import { runFinalize, runQueries } from "./analyze";
import { determineAutobuildLanguage, runAutobuild } from "./autobuild";
@ -197,7 +198,7 @@ program
// Wipe the temp dir
logger.info(`Cleaning temp directory ${tempDir}`);
fs.rmSync(tempDir, { recursive: true, force: true });
await del(tempDir, { force: true });
fs.mkdirSync(tempDir, { recursive: true });
const auth = await getGitHubAuth(

View file

@ -7,6 +7,7 @@ import { IHeaders } from "@actions/http-client/interfaces";
import * as io from "@actions/io";
import * as actionsToolcache from "@actions/tool-cache";
import * as safeWhich from "@chrisgavin/safe-which";
import del from "del";
import * as semver from "semver";
import { v4 as uuidV4 } from "uuid";
@ -121,7 +122,13 @@ export async function cacheDir(
throw new Error("sourceDir is not a directory");
}
// Create the tool dir
const destPath = createToolPath(tool, version, arch, toolCacheDir, logger);
const destPath = await createToolPath(
tool,
version,
arch,
toolCacheDir,
logger
);
// copy each child item. do not move. move can fail on Windows
// due to anti-virus software having an open handle on a file.
for (const itemName of fs.readdirSync(sourceDir)) {
@ -253,13 +260,13 @@ function createExtractFolder(tempDir: string): string {
return dest;
}
function createToolPath(
async function createToolPath(
tool: string,
version: string,
arch: string,
toolCacheDir: string,
logger: Logger
): string {
): Promise<string> {
const folderPath = path.join(
toolCacheDir,
tool,
@ -268,8 +275,8 @@ function createToolPath(
);
logger.debug(`destination ${folderPath}`);
const markerPath = `${folderPath}.complete`;
fs.rmSync(folderPath, { recursive: true, force: true });
fs.rmSync(markerPath, { recursive: true, force: true });
await del(folderPath, { force: true });
await del(markerPath, { force: true });
fs.mkdirSync(folderPath, { recursive: true });
return folderPath;
}

View file

@ -4,6 +4,7 @@ import * as path from "path";
import { Readable } from "stream";
import * as core from "@actions/core";
import del from "del";
import * as semver from "semver";
import { getApiClient, GitHubApiDetails } from "./api-client";
@ -73,7 +74,7 @@ export async function withTmpDir<T>(
const symlinkSubdir = path.join(tmpDir, "symlink");
fs.symlinkSync(realSubdir, symlinkSubdir, "dir");
const result = await body(symlinkSubdir);
fs.rmSync(tmpDir, { recursive: true, force: true });
await del(tmpDir, { force: true });
return result;
}
@ -565,7 +566,7 @@ export async function bundleDb(
// from somewhere else or someone trying to make the action upload a
// non-database file.
if (fs.existsSync(databaseBundlePath)) {
fs.rmSync(databaseBundlePath, { recursive: true });
await del(databaseBundlePath);
}
await codeql.databaseBundle(databasePath, databaseBundlePath);
return databaseBundlePath;