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

Make "Linking dependencies" faster on Windows (in some cases) #2958

Merged
merged 1 commit into from
Apr 3, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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