MCPcopy Create free account
hub / github.com/garrytan/gstack / rotateIfNeeded

Function rotateIfNeeded

browse/src/security.ts:370–388  ·  view source on GitHub ↗

* Rotate attempts.jsonl when it exceeds 10MB. Keeps 5 generations.

()

Source from the content-addressed store, hash-verified

368 * Rotate attempts.jsonl when it exceeds 10MB. Keeps 5 generations.
369 */
370function rotateIfNeeded(): void {
371 try {
372 const st = fs.statSync(ATTEMPTS_LOG);
373 if (st.size < MAX_LOG_BYTES) return;
374 } catch {
375 return; // doesn't exist, nothing to rotate
376 }
377 // Shift .N -> .N+1, drop oldest
378 for (let i = MAX_LOG_GENERATIONS - 1; i >= 1; i--) {
379 const src = `${ATTEMPTS_LOG}.${i}`;
380 const dst = `${ATTEMPTS_LOG}.${i + 1}`;
381 try {
382 if (fs.existsSync(src)) fs.renameSync(src, dst);
383 } catch {}
384 }
385 try {
386 fs.renameSync(ATTEMPTS_LOG, `${ATTEMPTS_LOG}.1`);
387 } catch {}
388}
389
390/**
391 * Try to locate the gstack-telemetry-log binary. Resolution order matches

Callers 1

logAttemptFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected