Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit 8461f55c00abf1b30bf46099b9800f5b39bdb39d
parent 14e3e298d739855dc671a2bd682c28691e71a728
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 11 Nov 2026 08:20:07 -0500

archives: the disk cache writes through atomicFile's temp names (demo epic D1 item 6)

test:scripts' sweep (no temp name made by hand) caught the cache's
`<file>.<pid>.<ms>.tmp`: its documents and their meta now go through
writeFileAtomic, and the prune skips the `.tmp-` names.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Diffstat:
Mcommon/lib/archiveCache-server.ts | 14++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/common/lib/archiveCache-server.ts b/common/lib/archiveCache-server.ts @@ -35,9 +35,10 @@ // are dropped. Never transcripts/ (it is the corpus), never /tmp (it is RAM). import { createHash } from "node:crypto"; -import { mkdir, readdir, readFile, rename, rm, stat, utimes, writeFile } from "node:fs/promises"; +import { mkdir, readdir, readFile, rm, stat, utimes } from "node:fs/promises"; import path from "node:path"; import { getPaths } from "./paths"; +import { writeFileAtomic } from "./atomicFile.mjs"; import { plainGetJson, type FetchLike, type GetJson } from "./remoteArchives-server"; export const CORPUS_TTL_MS = 10 * 60_000; @@ -164,11 +165,8 @@ export class ArchiveDiskCache { private async keep(file: string, body: string, meta: Meta): Promise<void> { await mkdir(path.dirname(file), { recursive: true }); - const tmp = `${file}.${process.pid}.${this.now()}.tmp`; - await writeFile(tmp, body); - await rename(tmp, file); - await writeFile(`${tmp}.meta`, JSON.stringify(meta)); - await rename(`${tmp}.meta`, `${file}.meta.json`); + await writeFileAtomic(file, body); + await writeFileAtomic(`${file}.meta.json`, JSON.stringify(meta)); if (++this.writes % 20 === 1) await this.prune().catch(() => {}); } @@ -206,7 +204,7 @@ export class ArchiveDiskCache { this.stats.notModified += 1; const g = corpus ? undefined : (generation ?? (await this.generationOf(base))); const next: Meta = { ...meta, checkedAt: this.now(), ...(corpus ? {} : { generation: g ?? meta.generation ?? null }) }; - await writeFile(`${file}.meta.json`, JSON.stringify(next)).catch(() => {}); + await writeFileAtomic(`${file}.meta.json`, JSON.stringify(next)).catch(() => {}); return this.fromDisk(file, next, base, corpus, true); } if (!res.ok) { @@ -253,7 +251,7 @@ export class ArchiveDiskCache { for (const sub of await readdir(this.dir).catch(() => [] as string[])) { const d = path.join(this.dir, sub); for (const name of await readdir(d).catch(() => [] as string[])) { - if (name.endsWith(".meta.json") || name.endsWith(".tmp") || name.endsWith(".meta")) continue; + if (name.endsWith(".meta.json") || name.includes(".tmp-")) continue; const st = await stat(path.join(d, name)).catch(() => null); if (st?.isFile()) files.push({ file: path.join(d, name), bytes: st.size, at: st.mtimeMs }); }