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>
This commit is contained in:
Matt Isenhower 2026-02-22 09:27:00 -08:00
parent 41c9f9a315
commit e6e96ac8f9
3 changed files with 8 additions and 30 deletions

View File

@ -6,32 +6,29 @@ export function mkdirp(dir) {
}
export async function exists(file) {
const vfsResult = vfs.has(file);
if (vfsResult !== null) {
return vfsResult;
}
try {
await fs.access(file);
return true;
} catch (e) {
return false;
// 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) {
const mtime = vfs.getMtime(file);
if (mtime !== null) {
return mtime < 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;
}
}

View File

@ -103,23 +103,6 @@ class VirtualFileSystem {
return entry ? entry.lastModified : null;
}
/**
* Track a file that was just written locally.
* Ensures subsequent has() calls return true without hitting disk.
* @param {string} localPath
*/
track(localPath) {
if (!this._loaded) return;
const key = this._localPathToKey(localPath);
if (key === null) return;
this._listing.set(key, {
lastModified: new Date(),
size: 0,
});
}
/**
* Convert a local path (e.g. 'dist/assets/splatnet/foo.png')
* to an S3 key (e.g. 'assets/splatnet/foo.png').

View File

@ -4,7 +4,6 @@ import PQueue from 'p-queue';
import prefixedConsole from '../common/prefixedConsole.mjs';
import { normalizeSplatnetResourcePath } from '../common/util.mjs';
import { exists, mkdirp } from '../common/fs.mjs';
import vfs from '../common/vfs.mjs';
const queue = new PQueue({ concurrency: 4 });
@ -72,7 +71,6 @@ export default class ImageProcessor
await mkdirp(path.dirname(this.localPath(destination)));
await fs.writeFile(this.localPath(destination), result.body);
vfs.track(this.localPath(destination));
} catch (e) {
this.console.error(`Image download failed for ${destination}`, e);
}