Skip to content

Commit

Permalink
Avoid node issue with utimes on Windows
Browse files Browse the repository at this point in the history
Lot of nodejs versions are buggy on windows regarding utime : It's not
setting the milliseconds part.

Issue: nodejs/node#2069

With this change file date comparison is now done with only seconds
precision on windows when copying files. It make linking fast again under
windows.
  • Loading branch information
vbfox committed Mar 20, 2017
1 parent 6e9a9a6 commit 4854357
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/util/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,29 @@ type CopyOptions = {
artifactFiles: Array<string>,
};

let fileDatesEqual = (a: Date, b: Date) => {
return a.getTime() === b.getTime();
};

if (os.platform() === 'win32') {
fileDatesEqual = (a: Date, b: Date) => {
const aTime = a.getTime();
const bTime = b.getTime();
const aTimeSec = Math.floor(aTime / 1000);
const bTimeSec = Math.floor(bTime / 1000);

// See https://github.com/nodejs/node/issues/2069
// Some versions of Node on windows zero the milliseconds when utime is used
// So if any of the time has a milliseconds part of zero we suspect that the
// bug is present and compare only seconds.
if ((aTime - aTimeSec * 1000 === 0) || (bTime - bTimeSec * 1000 === 0)) {
return aTimeSec === bTimeSec;
}

return aTime === bTime;
};
}

async function buildActionsForCopy(
queue: CopyQueue,
events: CopyOptions,
Expand Down Expand Up @@ -162,7 +185,7 @@ async function buildActionsForCopy(
}
}

if (bothFiles && srcStat.size === destStat.size && +srcStat.mtime === +destStat.mtime) {
if (bothFiles && srcStat.size === destStat.size && fileDatesEqual(srcStat.mtime, destStat.mtime)) {
// we can safely assume this is the same file
onDone();
reporter.verbose(reporter.lang('verboseFileSkip', src, dest, srcStat.size, +srcStat.mtime));
Expand Down

0 comments on commit 4854357

Please sign in to comment.