Skip to content

[NODEFS] Pass timestamps in seconds to utimes instead of Date instances - #27787

Merged
sbc100 merged 1 commit into
emscripten-core:mainfrom
sbc100:nodefs_utimes_seconds
Sep 28, 2026
Merged

sbc100 merged 1 commit into
emscripten-core:mainfrom
sbc100:nodefs_utimes_seconds

Conversation

@sbc100

@sbc100 sbc100 commented Sep 26, 2026

Copy link
Copy Markdown
Collaborator

Node's fs.utimesSync, fs.lutimesSync, and fs.futimesSync accept timestamps either as Date instances or as numbers in seconds.

Passing seconds directly has multiple advantages:

  1. Avoids allocating two temporary Date instances on each setattr.
  2. Preserves sub-millisecond timestamp precision down to the host filesystem call rather than quantizing to integer milliseconds.
  3. Aligns NODEFS with NODERAWFS, which already passes timestamps in seconds.
  4. When preserving unspecified timestamps, reads atimeMs / mtimeMs instead of atime / mtime Date objects from stat(arg).

This may also help reduce flakiness in timestamp tests (such as test_futimens) when converting and checking sub-millisecond precision.

See: #25280

Node's `fs.utimesSync`, `fs.lutimesSync`, and `fs.futimesSync` accept
timestamps either as `Date` instances or as numbers in seconds.

Passing seconds directly has multiple advantages:
1. Avoids allocating two temporary `Date` instances on each `setattr`.
2. Preserves sub-millisecond timestamp precision down to the host
   filesystem call rather than quantizing to integer milliseconds.
3. Aligns `NODEFS` with `NODERAWFS`, which already passes timestamps
   in seconds.
4. When preserving unspecified timestamps, reads `atimeMs` / `mtimeMs`
   instead of `atime` / `mtime` `Date` objects from `stat(arg)`.

This may also help reduce flakiness in timestamp tests (such as
`test_futimens`) when converting and checking sub-millisecond precision.

See: emscripten-core#25280
@sbc100
sbc100 force-pushed the nodefs_utimes_seconds branch from 4813628 to f76d1fc Compare September 28, 2026 00:20
@sbc100
sbc100 merged commit 4134523 into emscripten-core:main Sep 28, 2026
42 checks passed
@sbc100
sbc100 deleted the nodefs_utimes_seconds branch September 28, 2026 19:43
sbc100 pushed a commit that referenced this pull request Oct 6, 2026
`MEMFS.node_ops.getattr` returned the times only as `Date` objects,
which hold whole milliseconds, so `stat()` truncated them even after
`utimensat()` had stored a sub-millisecond value (#27794 keeps 10 µs). 
This also returns `atimeMs`/`mtimeMs`/`ctimeMs` with the exact values,
as NODEFS does since #27787, and lets `SYSCALLS.writeStat` prefer the
`*Ms` properties in every environment, not only when 
`ENVIRONMENT_MAY_BE_NODE` (MEMFS is used in the
browser too). The `Date` properties stay, for JS users of `FS.stat`.

The new test (`test_fs_subms_times`, all filesystems) sets a time with
`utimensat()` and reads it back with `stat()` and `fstat()`; before this
change only the MEMFS variant failed. Checked as well with
`-sENVIRONMENT=web` in Chromium (`.123000000` before, `.123449951`
after).

Codesize: +54 bytes of JS where MEMFS is included; wasm unchanged.

Not included: the second suggestion in the issue (stamping files with a
sub-millisecond clock instead of `Date.now()`), which touches more
places and changes behaviour; happy to do it as a follow-up if wanted.

Fixes: #27885
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants