src: round nsec instead of truncating stat times
Truncation of submillisecond timestamp accuracy on windows creates situations where attempting to change access or modification times becomes off by one ms. Example:
var fs = require('fs');
var targetMTime = new Date('2017-04-08T17:59:38.008Z');
fs.writeFileSync("./file1", "");
fs.utimesSync("./file1", targetMTime, targetMTime);
var actualMTime = fs.statSync("./file1").mtime;
console.log(actualMTime); // 2017-04-08T17:59:38.007Z
console.log(actualMTime.getTime() === targetMTime.getTime()); // false
This PR fixes the issue by rounding nsec rather than truncating in node_file.cc. A concern with that is that stat is a rather hot bit of code.. adding in 4 rounding operations could make a noticeable difference.
Another option could be to increment the return from toUnixTimestamp in fs.js enough to offset the precision loss, that would at least fix the issue if only node processes are updating the files.. but not particularly robust.
A third solution is to ignore the problem. It likely isn't something that affects that many users.
Checklist
-
make -j4 test
(UNIX), orvcbuild test
(Windows) passes -
tests and/or benchmarks are included -
commit message follows commit guidelines
Affected core subsystem(s)
src