-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Access and Modify time stats are preserved from source files #1461
Comments
dest
preserves access
and modify
time from source files
Thanks for filing this. It is on our radar over at gulpjs/vinyl-fs#128 but changes need to be made in the content setter of https://github.com/gulpjs/vinyl to update the stat times when contents are changed. |
Thanks for pointing me there. I've read the discussion and it seems to reach rather deep into vinyl internals. I'd love to help there, but I don't think I'm up to it ATM. In case anybody bumps into this superficial issue of gulp-4 here is my quick and dirty workaround until it gets resolved in vinyl-fs. // ...
var hrough = require('through2');
var utimes = require('fs').utimes;
var touch = through.obj(function(file, enc, done) {
var now = new Date;
utimes(file.path, now, now, done);
});
// ...
gulp.task ("process", function() {
return gulp
.src("file.txt")
.pipe(gulp.dest("dest/"))
.pipe(touch)
}); |
@lzrski you can actually modify the |
@phated works, thanks :) This may be a very lame question so excuse my ignorance: Can't Maybe at least before you guys come up with more clever solution in vinyl / vinyl-fs you can cut one corner here and then take time necessary to engineer it better. You said it's the last roadblock and I'm sure there are lots of people who would love to see Gulp 4 released. In case my question is too dumb to answer just say so and I'll shut up :) Anyway Gulp is absolutely great and I use it every day. Thanks for that. |
Touch helper that sets `file.stat.mtime` to current time (gulpfile.d/helpers/touch). Used in `teacup` and `style` tasks.
I've been digging into *nix commands (namely |
+1 The only use case for preserving mtime I can think of is for static assets, i.e. files that get copied from src to dest without modification. Here preserving is good for browsers cache. But I would argue that this is an exception, so flag is a good idea. On the other hand using getters and setters in vinyl object is way more elegant. It mimics real filesystem behaviour. How hard do you think that would be? Should I try a PR there or will I drown in complexity? |
@lzrski vinyl is a much simpler library than vinyl-fs. Most code, expect some utility functions, is in the single |
@phated @lzrski FYI I had already started on this a few days back, in the getter/setter of I didn't add a By the way, if we're looking at command line primitives for inspiration, wouldn't it be a better match with how gulp works to consider something like |
@erikkemperman can you submit a PR with your work to |
@phated Yeah, couple of problems here unfortunately... Laptop died during the holidays, so I will need to re-do what I'd done earlier. But in the meantime it also occurred to me that I might have been approaching this too shallow. What I'd done is just to set the Then there is Thing is I don't see how to do any of this without ugly monkeypatching stream and buffer methods. So I could make a PR of the simple case pretty quickly but I think that might not be sufficient. Any ideas? |
@erikkemperman that's terrible about your laptop. I think the shallow case might be fine along with some documentation updates. We've always recommended the following patterns: // Buffers
var contents = file.contents.toString();
// modify contents
file.contents = new Buffer(contents);
// Streams
file.contents = file.contents.pipe(someTransform); If the documentation was updated to explain that the reassignment always needs to happen and why, we can get away with the shallow implementation. I had thought about the mode, uid and gid which is why I started https://github.com/gulpjs/better-stats but got hung up on some details and where to go with it. |
@phated Appreciate the sentiment -- actually it was a small miracle that it didn't happen before, it was pretty old. Back to desktop, for now. Anyway, I've been thinking about the "deep" approach a little more, and having noticed this issue about Probably you're right that the shallow approach would cover a pretty large area of use cases. I'm having a hard time thinking of anything but contrived exceptions. I'll make a PR for that shortly. But then I'll likely still want to try finding a more comprehensive approach... This metadata stuff somehow feels like it deserves a pretty thorough design. Our talk of mimicking I get that people want something out there, but would the |
Thanks for following up so quickly. Once we publish 4.0.0 to npm with the next tag, we can't do anything breaking, just bug fixes and features. I think we need to land the basic functionality in vinyl so vinyl-fs is outputting correct timestamps. |
…release this solves an issue of the modified time not changing gulpjs/gulp#1461 (comment)
Just upgraded to gulp 4, and I'm still seeing this (2+ years later). Fixed with gulp-touch-fd, but are there any plans to really fix this? |
@JacobDB this behavior is due to supporting |
If you run following gulpfile with Gulp 4 (current HEAD) you will get
dest/file.txt
withAccess
andModification
time preserved from source, (file.txt
; January 1st 1970). I believe this is wrong - the modification time should reflect the time when each destination file was written by Gulp.This is mostly problematic with plugins that only read one file, but this file depends on other files to produce a single output, e.g. gulp-stylus. In my case I pass only
main.styl
file togulp.src
and inside of it I have some@import
statements. Changes to imported files trigger a task, but final CSS file has modification time ofmain.styl
which seldom changes. This is causing issues with browsers cache - I get304 Not Modified
from my webserver.Here is a sample
gulpfile.js
to reporduce the issue:Equivalent file executed with v. 3 produces correct (IMO) output.
edit: Wrong argument was passed to stat command (%x instead of %y). Fixed.
The text was updated successfully, but these errors were encountered: