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

.dest : mtime/atime lose sub-second precision #124

Closed
erikkemperman opened this issue Nov 5, 2015 · 8 comments
Closed

.dest : mtime/atime lose sub-second precision #124

erikkemperman opened this issue Nov 5, 2015 · 8 comments

Comments

@erikkemperman
Copy link
Member

When .dest writes to file, the atime and mtime get rounded (well, floored) to seconds, even when the filesystem supports subsecond precision.

Example gulpfile.js:

// Bogus plugin to print mtimes
function meta() {
  return through.obj(function( file, enc, cb) {
    console.log(file.stat.mtime.valueOf());
    this.push(file);
    cb();
  });
}

gulp.task('test1', function() {
  return gulp.src('./src/foo.js')
    .pipe(meta())
    .pipe(gulp.dest('./dist/'))
});

gulp.task('test2', function() {
  return gulp.src('./dist/foo.js')
    .pipe(meta());
});

gulp.task('default', gulp.series('test1', 'test2'));

the above would output something like this:

[17:09:00] Starting 'default'...
[17:09:00] Starting 'test1'...
1442829863383
[17:09:00] Finished 'test1' after 22 ms
[17:09:00] Starting 'test2'...
1442829863000
[17:09:00] Finished 'test2' after 4.88 ms
[17:09:00] Finished 'default' after 29 ms

This is problematic when using plugins like gulp-changed or gulp-newer, e.g. when we want to copy source files to a dist directory only if they've changed.

I've tracked this down to the fact that fs.utimes is called. Apparently the problem would go away if fs.futimes were called, see here. I just did some quick-and-dirty experimenting which confirms that this is the case.

Even better, I suppose, would be to fix utimes, see here, but I think that might not happen any time soon.

I'd be willing to make a PR which would make vinyl-fs use futimes but wanted to check first if this sounds like a good idea, or maybe there might be other solutions I'm overlooking.

@phated
Copy link
Member

phated commented Nov 5, 2015

@erikkemperman in the linked node issue, it says there is a caveat of filesystems that don't support subsecond resolution. What does futimes do in those cases?

@erikkemperman
Copy link
Member Author

@phated I think he's just saying that using fs.futimes in stead of fs.utimes won't solve your problem of retaining fractions of a second -- if the filesystem you have underneath doesn't support it. I have no fs at hand to test this case... But surely no fs will cause the atime and mtime to be in seconds, in stead of millis, or something like that?

@phated
Copy link
Member

phated commented Nov 5, 2015

I'll try to run the tests on windows to see what happens. Think I have a VM lying around somewhere.

@erikkemperman
Copy link
Member Author

With a FAT partition? NTFS would not have this problem, right?

I'm curious how that turns out. My guess is it will just work as if every read/write happened at precisely .000 millis, which is pretty much what it did before my patch.

@phated
Copy link
Member

phated commented Nov 5, 2015

Blah, no luck with that VM. I'm going to get this merged under the assumption it just rounds 😛

@erikkemperman
Copy link
Member Author

Probably not too many people use an fs which might be affected...? Famous last words.

Anyway, great if it got merged!

@phated
Copy link
Member

phated commented Nov 5, 2015

@erikkemperman just needs a rebase (commented on PR)

@phated
Copy link
Member

phated commented Nov 6, 2015

Closed by #125 - grouping some other fixes in a release.

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