Skip to content

Commit 6a1b2e8

Browse files
committed
playground: stamp updatedb database with current time
Running the new locate/updatedb tests on real wasm surfaced a UX bug: updatedb writes its database into the virtual filesystem with epoch (1970) timestamps, so every subsequent locate warned "database is more than 8 days old (actual age is 20626.6 days)". That warning also went to stderr, which the dispatcher merges into the result and treats as pipeline-ending, breaking `locate ... | ...`. Stamp the freshly-built database with "now" (same stat() patch used for the sample files) so locate stays quiet and its stderr stays empty.
1 parent 2cddc81 commit 6a1b2e8

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

static/js/wasm-terminal.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,21 @@ function readVirtualFile(name) {
524524
return new TextDecoder().decode(file.data);
525525
}
526526

527+
/**
528+
* Stamp a virtual file's timestamps with "now". browser_wasi_shim creates
529+
* files written by a WASM command (e.g. updatedb's database) with epoch (1970)
530+
* timestamps; this patches stat() the same way getPersistentDir does for the
531+
* sample files, so age-sensitive readers (locate) don't see a decades-old file.
532+
*/
533+
function touchVirtualFileNow(name) {
534+
const dir = getPersistentDir();
535+
const file = dir.dir.contents.get(resolvePath(name));
536+
if (!file || typeof file.stat !== "function") return;
537+
const nowNs = BigInt(Date.now()) * 1_000_000n;
538+
const orig = file.stat.bind(file);
539+
file.stat = () => { const s = orig(); s.atim = nowNs; s.mtim = nowNs; s.ctim = nowNs; return s; };
540+
}
541+
527542
/**
528543
* Write a file to the virtual filesystem.
529544
*/
@@ -727,6 +742,14 @@ async function executeCommandLine(line) {
727742
}
728743
const wasmArgs = isStandalone ? dispatchArgs : ["coreutils", ...resolvedArgs];
729744
const result = await runCommand(wasmArgs, stdinData, isStandalone ? standaloneModules[moduleName] : wasmModule);
745+
// updatedb writes its database with epoch (1970) timestamps in the virtual
746+
// FS, so a later `locate` would warn the db is decades old (and that stderr
747+
// warning would break `locate … | …` pipes). Stamp the freshly-built db
748+
// with "now" to keep locate quiet.
749+
if (cmd === "updatedb" && result.exitCode === 0) {
750+
const outArg = resolvedArgs.find(a => a.startsWith("--output="));
751+
touchVirtualFileNow(outArg ? outArg.slice("--output=".length) : LOCATE_DB);
752+
}
730753
if (result.stderr) {
731754
return result.stderr + result.stdout;
732755
}

0 commit comments

Comments
 (0)