Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utimes should support undefined arguments to leave the time alone #56492

Open
hoodmane opened this issue Jan 6, 2025 · 3 comments
Open

utimes should support undefined arguments to leave the time alone #56492

hoodmane opened this issue Jan 6, 2025 · 3 comments
Labels
feature request Issues that request new features to be added to Node.js.

Comments

@hoodmane
Copy link

hoodmane commented Jan 6, 2025

What is the problem this feature will solve?

Sometimes one only wants to modify access time, not modification time or vice versa.

I'm working on the Emscripten where we have an implementation of a linux file system backed by the node fs module. The utimens family of functions are supposed to leave the time value alone if UTIME_OMIT is passed in the nanosecond field.

What is the feature you are proposing to solve the problem?

It would be convenient if FS.utime(path, atime, undefined) would update the atime and leave the mtime alone, and vice versa.

node uses libuv to call utimens itself, but the libuv api only takes doubles and converts from them to fill the tv_nsec struct with uv__fs_to_timeval. It's not possible to make a double that is converted to UTIME_OMIT because uv__fs_to_timeval rounds the nanosecond field: https://github.com/libuv/libuv/blame/v1.x/src/unix/fs.c#L216. So libuv would need to be updated to support this. At the same time it could also be changed to support higher precision times #50859.

What alternatives have you considered?

Stat the file and use the stat to fill the time I want unchanged. Because of #50859, this will round trip the time through a double and so leave it only approximately unchanged not exactly unchanged.

@hoodmane hoodmane added the feature request Issues that request new features to be added to Node.js. label Jan 6, 2025
@github-project-automation github-project-automation bot moved this to Awaiting Triage in Node.js feature requests Jan 6, 2025
@hoodmane
Copy link
Author

hoodmane commented Jan 6, 2025

cc @bnoordhuis

@cjihrig
Copy link
Contributor

cjihrig commented Jan 6, 2025

It's probably worth discussing this on the libuv issue tracker first. I think we'd also need some cross-platform UTIME_OMIT support since libuv tries to provide a uniform API across platforms.

@hoodmane
Copy link
Author

hoodmane commented Jan 6, 2025

Opened upstream libuv/libuv#4665

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js.
Projects
Status: Awaiting Triage
Development

No branches or pull requests

2 participants