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

compareLastModifiedTime does not work in Windows #49

Open
dmschlot opened this issue Nov 8, 2015 · 2 comments
Open

compareLastModifiedTime does not work in Windows #49

dmschlot opened this issue Nov 8, 2015 · 2 comments

Comments

@dmschlot
Copy link

dmschlot commented Nov 8, 2015

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
Copy link
Author

dmschlot commented Nov 9, 2015

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
Copy link

Was this ever done?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants