mirror of
https://github.com/github/codeql-action.git
synced 2025-12-31 11:40:24 +08:00
TRAP Caching: Skip uploading of small caches
This commit is contained in:
22
src/util.ts
22
src/util.ts
@@ -2,9 +2,11 @@ import * as fs from "fs";
|
||||
import * as os from "os";
|
||||
import * as path from "path";
|
||||
import { Readable } from "stream";
|
||||
import { promisify } from "util";
|
||||
|
||||
import * as core from "@actions/core";
|
||||
import del from "del";
|
||||
import getFolderSize from "get-folder-size";
|
||||
import * as semver from "semver";
|
||||
|
||||
import * as api from "./api-client";
|
||||
@@ -836,3 +838,23 @@ export async function isGoExtractionReconciliationEnabled(
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size a folder in bytes. This will log any filesystem errors
|
||||
* as a warning and then return undefined.
|
||||
*
|
||||
* @param cacheDir A directory to get the size of.
|
||||
* @param logger A logger to log any errors to.
|
||||
* @returns The size in bytes of the folder, or undefined if errors occurred.
|
||||
*/
|
||||
export async function tryGetFolderBytes(
|
||||
cacheDir: string,
|
||||
logger: Logger
|
||||
): Promise<number | undefined> {
|
||||
try {
|
||||
return await promisify<string, number>(getFolderSize)(cacheDir);
|
||||
} catch (e) {
|
||||
logger.warning(`Encountered an error while getting size of folder: ${e}`);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user