openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
43 lines (42 loc) • 1.06 kB
JavaScript
import fs from "node:fs";
import { tryAcquireWriteLease } from "@openclaw/fs-safe/file-lock";
//#region src/agents/worktrees/git-pack-cleanup.worker.ts
process.on("SIGIO", () => {});
const { files, olderThan } = JSON.parse(fs.readFileSync(0, "utf8"));
let removed = 0;
let retained = 0;
for (const e of files) {
if (removed >= 256) break;
let t;
try {
t = fs.openSync(e, fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW | fs.constants.O_NONBLOCK);
const n = fs.fstatSync(t);
if (!n.isFile() || n.mtimeMs >= olderThan) continue;
const r = tryAcquireWriteLease(t);
if (!r) {
retained++;
continue;
}
try {
const t = fs.lstatSync(e);
if (t.dev !== n.dev || t.ino !== n.ino || t.size !== n.size || t.mtimeMs !== n.mtimeMs || t.ctimeMs !== n.ctimeMs || !r.isHeld()) {
retained++;
continue;
}
fs.unlinkSync(e);
removed++;
} finally {
r.release();
}
} catch {
retained++;
} finally {
if (t !== void 0) fs.closeSync(t);
}
}
process.stdout.write(JSON.stringify({
removed,
retained
}));
//#endregion
export {};