Skip to content

Commit 057ada0

Browse files
committed
accept 1ms difference in filedates as equal on windows
a nodejs issue causes certain dates to be off by 1ms after calling utimes See: nodejs/node#12607
1 parent bb927d0 commit 057ada0

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

__tests__/util/fs.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ describe('fileDatesEqual', () => {
3939
});
4040

4141
test('Different dates differ', () => {
42-
expect(fileDatesEqual(new Date(1491393798834), new Date(1491393798835))).toBeFalsy();
42+
expect(fileDatesEqual(new Date(1491393798834), new Date(1491393798835))).toBeTruthy();
43+
expect(fileDatesEqual(new Date(1491393798834), new Date(1491393798836))).toBeFalsy();
4344
expect(fileDatesEqual(new Date(1491393700834), new Date(1491393798834))).toBeFalsy();
4445
});
4546

src/util/fs.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ export const fileDatesEqual = (a: Date, b: Date) => {
8888
return aTime === bTime;
8989
}
9090

91+
// See https://github.com/nodejs/node/pull/12607
92+
// Submillisecond times from stat and utimes are truncated on Windows,
93+
// causing a file with mtime 8.0079998 and 8.0081144 to become 8.007 and 8.008
94+
// and making it impossible to update these files to their correct timestamps.
95+
if (Math.abs(aTime - bTime) <= 1) {
96+
return true;
97+
}
98+
9199
const aTimeSec = Math.floor(aTime / 1000);
92100
const bTimeSec = Math.floor(bTime / 1000);
93101

0 commit comments

Comments
 (0)