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

Provide access to file system times with nanoseconds resolution #8276

Closed
haraldrudell opened this issue Aug 26, 2016 · 6 comments · Fixed by #13173
Closed

Provide access to file system times with nanoseconds resolution #8276

haraldrudell opened this issue Aug 26, 2016 · 6 comments · Fixed by #13173
Labels
feature request Issues that request new features to be added to Node.js. fs Issues and PRs related to the fs subsystem / file system.

Comments

@haraldrudell
Copy link

haraldrudell commented Aug 26, 2016

Node.js should provide nanosecond time values in the fs.stat() response structure similar to how process.hrtime() does it.

If there is a module or trick to provide ns I would be happy to use that

Generally on Linux, human readable stat provides the nanoseconds, and epoch time provides the UTC second-level value. The combination is complete. Since Node.js uses ECMAScript Date objects, there is only millisecond resolution.

  • ext4 and Android has nanosecond time resolution since long time
  • Most Linux utilities still drop sub-seconds and Linux cannot display birth date easily
  • Some Android won't give you UTC allowing you to create lots of bugs calculating it

Here's Linux human readable

stat 0 --format %z
2016-06-14 00:50:44.920739523 -0700

uname --all && node --version
Linux c89 4.4.0-34-generic #53-Ubuntu SMP Wed Jul 27 16:06:39 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
v6.4.0

I have some utilities moving large data around that uses recursive md5 and metadata before-after to verify integrity

@mscdex mscdex added fs Issues and PRs related to the fs subsystem / file system. feature request Issues that request new features to be added to Node.js. labels Aug 26, 2016
@bnoordhuis
Copy link
Member

If there is a module or trick to provide ns I would be happy to use that

If there isn't one already, you can write your own bindings for uv_fs_stat/uv_fs_fstat/uv_fs_lstat. That is what node.js itself uses and they support nanosecond resolution on file systems that support them and with the usual caveats.

Adding nanoseconds to fs.Stats is something I'd probably veto because of the performance implications. They're already expensive to create; tacking on more properties would only make it worse.

It might be possible to do something clever with interceptors and create values lazily but that would have to be benchmarked very carefully.

@haraldrudell
Copy link
Author

The performance impact is to copy 4 C long to ECMAScript number

fs.*utimes() api needs update, too

  • some file properties are not supported here
  • it might be more future proof to use an object

@bnoordhuis
Copy link
Member

The performance impact is to copy 4 C long to ECMAScript number

With all due respect but that comment betrays a certain ignorance of node's and V8's inner workings.

@haraldrudell
Copy link
Author

Both nanoseconds (kernel 2.6) and birth date (ext4) predates Node.js

These fs api calls should not have been designed this way in the first place. They knowingly lack file system features. The design of fs.*utimes does not adhere to good software engineering practices.

Additional constructive suggestions would be great!

@bnoordhuis
Copy link
Member

I already provided one:

It might be possible to do something clever with interceptors and create values lazily but that would have to be benchmarked very carefully.

@refack
Copy link
Contributor

refack commented Apr 25, 2017

In #12607 we are considering exposing the raw numbers in addition to the Date values

@refack refack mentioned this issue May 4, 2017
4 tasks
refack added a commit to refack/node that referenced this issue Jun 4, 2017
* convert ’ to ' to turn md file to ASCII

Fixes: nodejs#8276
Refs: nodejs#12607
Refs: nodejs#12818
Refs: nodejs#13256
refack added a commit to refack/node that referenced this issue Jun 7, 2017
PR-URL: nodejs#13173
Fixes: nodejs#8276
Refs: nodejs#12607
Refs: nodejs#12818
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Brian White <mscdex@mscdex.net>
jasnell pushed a commit that referenced this issue Jun 7, 2017
PR-URL: #13173
Fixes: #8276
Refs: #12607
Refs: #12818
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Brian White <mscdex@mscdex.net>
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. fs Issues and PRs related to the fs subsystem / file system.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants