post: simplify and rename totalSize

...and add some more logging. Related to #45.
This commit is contained in:
mlugg
2025-06-29 16:52:12 +01:00
parent e819eaaa44
commit cab58101cf
+12 -10
View File
@@ -19,7 +19,7 @@ async function main() {
if (accessible) {
core.info('Checking cache size');
const size = await totalSize(cache_path);
const size = await dirSize(cache_path);
const size_limit = core.getInput('cache-size-limit') * 1024 * 1024; // MiB -> bytes
if (size_limit !== 0 && size > size_limit) {
core.info(`Cache directory reached ${size} bytes, exceeding limit of ${size_limit} bytes; clearing cache`);
@@ -35,6 +35,8 @@ async function main() {
const name = prefix + github.context.runId;
core.info('Saving Zig cache');
await cache.saveCache([cache_path], name);
} else {
core.info('Zig cache directory is inaccessible; nothing to save');
}
}
} catch (err) {
@@ -42,18 +44,18 @@ async function main() {
}
}
async function totalSize(p) {
async function dirSize(dir_path) {
try {
const stat = await fs.stat(p);
if (stat.isFile()) return stat.size;
if (stat.isDirectory()) {
let total = 0;
for (const entry of await fs.readdir(p)) {
total += await totalSize(path.join(p, entry));
let total = 0;
for (const ent of await fs.readdir(dir_path, { withFileTypes: true, recursive: true })) {
if (ent.isFile()) {
try {
const stat = await fs.stat(path.join(ent.parentPath, ent.name));
total += stat.size;
} catch {}
}
return total;
}
return 0;
return total;
} catch {
return 0;
}