Skip to content

Commit

Permalink
accept 1ms difference in filedates as equal on windows (#3235)
Browse files Browse the repository at this point in the history
a nodejs issue causes certain dates to be off by 1ms after calling utimes

See: nodejs/node#12607
  • Loading branch information
sciolist authored and Daniel15 committed Apr 24, 2017
1 parent bb927d0 commit 18b15b6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion __tests__/util/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ describe('fileDatesEqual', () => {
});

test('Different dates differ', () => {
expect(fileDatesEqual(new Date(1491393798834), new Date(1491393798835))).toBeFalsy();
expect(fileDatesEqual(new Date(1491393798834), new Date(1491393798835))).toBeTruthy();
expect(fileDatesEqual(new Date(1491393798834), new Date(1491393798836))).toBeFalsy();
expect(fileDatesEqual(new Date(1491393700834), new Date(1491393798834))).toBeFalsy();
});

Expand Down
8 changes: 8 additions & 0 deletions src/util/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ export const fileDatesEqual = (a: Date, b: Date) => {
return aTime === bTime;
}

// See https://github.com/nodejs/node/pull/12607
// Submillisecond times from stat and utimes are truncated on Windows,
// causing a file with mtime 8.0079998 and 8.0081144 to become 8.007 and 8.008
// and making it impossible to update these files to their correct timestamps.
if (Math.abs(aTime - bTime) <= 1) {
return true;
}

const aTimeSec = Math.floor(aTime / 1000);
const bTimeSec = Math.floor(bTime / 1000);

Expand Down

0 comments on commit 18b15b6

Please sign in to comment.