Skip to content

fs: preserve exact nanoseconds in CopyUtimes on POSIX - #67405

Open
hazalkoom wants to merge 1 commit into
nodejs:mainfrom
hazalkoom:fix-66861-cp-sync-mtime
Open

hazalkoom wants to merge 1 commit into
nodejs:mainfrom
hazalkoom:fix-66861-cp-sync-mtime

Conversation

@hazalkoom

Copy link
Copy Markdown

When copying files with preserveTimestamps: true, CopyUtimes previously converted the source timespec integers into an IEEE-754 double of seconds before calling uv_fs_utime. At current epoch values, this resulted in sub-millisecond precision loss. If the original nanoseconds sat near a half-millisecond boundary, the loss caused the JS destination millisecond to round differently than the source.

This commit uses utimensat directly on POSIX to pass the exact tv_sec and tv_nsec integers from the source file to the destination, avoiding the floating-point conversion.

Fixes: #66861

Assisted-by: Antigravity antigravity@google.com

Copilot AI balanced review requested due to automatic review settings November 11, 2026 08:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to file-system APIs and the fs module. needs-ci PRs that need a full CI run. labels Nov 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Welcome to Node.js, and thank you for your first contribution!

Before review, please take a moment to read:

Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal.

When copying files with preserveTimestamps: true, CopyUtimes
previously converted the source timespec integers into an IEEE-754
double of seconds before calling uv_fs_utime. At current epoch
values, this resulted in sub-millisecond precision loss. If the
original nanoseconds sat near a half-millisecond boundary, the loss
caused the JS destination millisecond to round differently than
the source.

This commit uses utimensat directly on POSIX to pass the exact
tv_sec and tv_nsec integers from the source file to the
destination, avoiding the floating-point conversion.

Fixes: nodejs#66861
Signed-off-by: Mohamed Ahmed <mwhamd345@gmail.com>
Assisted-by: Antigravity <antigravity@google.com>
@hazalkoom
hazalkoom force-pushed the fix-66861-cp-sync-mtime branch from ecc854f to db4f5fd Compare November 11, 2026 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to file-system APIs and the fs module. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fs.cpSync with preserveTimestamps can give the copy an mtime in a different millisecond than the source

3 participants