sindresorhus / gulp-changed

Only pass through changed files
MIT License
742 stars 44 forks source link

compareLastModifiedTime does not work in Windows #49

Open dmschlot opened 9 years ago

dmschlot commented 9 years ago

The built in compareLastModifiedTime didn't work for me. On Windows the mtime of a file is rounded to seconds. Images created by people on a Mac, on the project I'm working on, have mliliseconds. When my task runs its creates the target file, and rounds milliseconds off. Subsequent runs it doesn't realize the source hasn't changed.

For example here is the source and target mtimes it was seeing. 1446818873134 > 1446818873000

Below is the method I used:

var compareLastModifiedTime = function(stream, cb, sourceFile, targetPath) {
    fs.stat(targetPath, function (err, targetStat) {
        if (targetStat === undefined) {
            stream.push(sourceFile);
        } else {
            var sourceMTime = sourceFile.stat.mtime / 1000 >> 0;
            var targetMTime = targetStat.mtime / 1000 >> 0;

            if (sourceMTime > targetMTime) {
                stream.push(sourceFile);
            }
        }
        cb();
    });
};

(NOTE: The bitwise math below is to round the float to an int. It's the quickest way according to: http://jsperf.com/math-floor-vs-math-round-vs-parseint/2)

Thanks, David

dmschlot commented 9 years ago

FYI - We found the issue also exists on Macs. We are working on a much more complete method now that only ignores milliseconds if the system doesn't keep them. We'll post it it later this.

Thanks!

mhornbacher commented 3 years ago

Was this ever done?