splatoon3.ink/app/common/fs.mjs
Matt Isenhower e6e96ac8f9 Check local disk before VFS, removing need for manual vfs.track()
exists() and olderThan() now check the local filesystem first and only
consult the VFS as a fallback. This means freshly written files are
found naturally without callers needing to register them.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 09:27:00 -08:00

35 lines
753 B
JavaScript

import fs from 'fs/promises';
import vfs from './vfs.mjs';
export function mkdirp(dir) {
return fs.mkdir(dir, { recursive: true });
}
export async function exists(file) {
try {
await fs.access(file);
return true;
} catch (e) {
// Not on local disk; check VFS (S3 listing) as fallback
return vfs.has(file) ?? false;
}
}
// Determine whether a file is older than a given cutoff date (or doesn't exist)
export async function olderThan(file, cutoff) {
try {
let stat = await fs.stat(file);
return stat.mtime < cutoff;
} catch (e) {
// Not on local disk; check VFS (S3 listing) as fallback
const mtime = vfs.getMtime(file);
if (mtime !== null) {
return mtime < cutoff;
}
return true;
}
}