Skip to content

Commit e83d90a

Browse files
committedMar 30, 2017
Avoid node issue with utimes on Windows
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.
1 parent 76c9fc1 commit e83d90a

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed
 

‎src/util/fs.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,29 @@ type CopyOptions = {
8080
artifactFiles: Array<string>,
8181
};
8282

83+
let fileDatesEqual = (a: Date, b: Date) => {
84+
return a.getTime() === b.getTime();
85+
};
86+
87+
if (os.platform() === 'win32') {
88+
fileDatesEqual = (a: Date, b: Date) => {
89+
const aTime = a.getTime();
90+
const bTime = b.getTime();
91+
const aTimeSec = Math.floor(aTime / 1000);
92+
const bTimeSec = Math.floor(bTime / 1000);
93+
94+
// See https://github.com/nodejs/node/issues/2069
95+
// Some versions of Node on windows zero the milliseconds when utime is used
96+
// So if any of the time has a milliseconds part of zero we suspect that the
97+
// bug is present and compare only seconds.
98+
if ((aTime - aTimeSec * 1000 === 0) || (bTime - bTimeSec * 1000 === 0)) {
99+
return aTimeSec === bTimeSec;
100+
}
101+
102+
return aTime === bTime;
103+
};
104+
}
105+
83106
async function buildActionsForCopy(
84107
queue: CopyQueue,
85108
events: CopyOptions,
@@ -162,7 +185,7 @@ async function buildActionsForCopy(
162185
}
163186
}
164187

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

0 commit comments

Comments
 (0)
Please sign in to comment.