diff --git a/lib/caching-utils.js b/lib/caching-utils.js new file mode 100644 index 000000000..63cd84550 --- /dev/null +++ b/lib/caching-utils.js @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getTotalCacheSize = getTotalCacheSize; +const util_1 = require("./util"); +/** + * Returns the total size of all the specified paths. + * @param paths The paths for which to calculate the total size. + * @param logger A logger to record some informational messages to. + * @returns The total size of all specified paths. + */ +async function getTotalCacheSize(paths, logger) { + const sizes = await Promise.all(paths.map((cacheDir) => (0, util_1.tryGetFolderBytes)(cacheDir, logger))); + return sizes.map((a) => a || 0).reduce((a, b) => a + b, 0); +} +//# sourceMappingURL=caching-utils.js.map \ No newline at end of file diff --git a/lib/caching-utils.js.map b/lib/caching-utils.js.map new file mode 100644 index 000000000..cc6155960 --- /dev/null +++ b/lib/caching-utils.js.map @@ -0,0 +1 @@ +{"version":3,"file":"caching-utils.js","sourceRoot":"","sources":["../src/caching-utils.ts"],"names":[],"mappings":";;AASA,8CAQC;AAhBD,iCAA2C;AAE3C;;;;;GAKG;AACI,KAAK,UAAU,iBAAiB,CACrC,KAAe,EACf,MAAc;IAEd,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,GAAG,CAC7B,KAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAA,wBAAiB,EAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAC7D,CAAC;IACF,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;AAC7D,CAAC"} \ No newline at end of file diff --git a/src/caching-utils.ts b/src/caching-utils.ts new file mode 100644 index 000000000..41a098a9a --- /dev/null +++ b/src/caching-utils.ts @@ -0,0 +1,18 @@ +import { Logger } from "./logging"; +import { tryGetFolderBytes } from "./util"; + +/** + * Returns the total size of all the specified paths. + * @param paths The paths for which to calculate the total size. + * @param logger A logger to record some informational messages to. + * @returns The total size of all specified paths. + */ +export async function getTotalCacheSize( + paths: string[], + logger: Logger, +): Promise { + const sizes = await Promise.all( + paths.map((cacheDir) => tryGetFolderBytes(cacheDir, logger)), + ); + return sizes.map((a) => a || 0).reduce((a, b) => a + b, 0); +}