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

Add option to preserve timestamps #141

Merged
merged 4 commits into from
Jun 26, 2015

Conversation

Narigo
Copy link
Contributor

@Narigo Narigo commented Jun 22, 2015

Another attempt to fix #138.
Hope this is better for you than PR #139

@jprichardson
Copy link
Owner

This looks really good, thank you!

  1. Yesterday, the copy tests were moved from ./test/copy to ./lib/copy/__tests__. Not a big deal, but would be cool if you could rebase. If you don't want to hassle with it, don't worry about it. I can patch that part up.
  2. It's interesting these pass on Node.js v0.10 on both Windows/Linux but fail on Node 0.12 / io.js. It looks like a millisecond precision difference. Any idea what's going on there?

@Narigo
Copy link
Contributor Author

Narigo commented Jun 22, 2015

I'm not sure if I check the dates correctly - I haven't really used mocha... probably the date check via assert.deepEqual doesn't work. It didn't pass the tests for me when using assert.equals, but with deepEqual it worked here locally...

I cloned the repo today and used the master branch. I didn't see the copy tests, so I just created one like move. Will move that though...

@jprichardson
Copy link
Owner

The formatting in my last comment butchered the path names, the copy tests were moved to ./lib/copy/__tests__. You can see the failed output on both Travis (Linux) and Appveyor (Windows). Both pass on Node v0.10, but fail in the rest due to the millisecond differences.

@Narigo
Copy link
Contributor Author

Narigo commented Jun 22, 2015

Any preference on where I should put the fixtures? Or shall I only test the copy of a single file?

@jprichardson
Copy link
Owner

Just be sure to reference or rebase against the latest master. If you need to create new fixtures, that's fine as well. Just put them in lib/copy/__tests__/fixtures/.

@Narigo Narigo force-pushed the preserve-timestamps branch from c9404aa to 2f7fb38 Compare June 22, 2015 13:35
@Narigo
Copy link
Contributor Author

Narigo commented Jun 22, 2015

Okay, I hope this will work out now. I've changed the equality check of the modification time / access time. I'm testing it on Node 0.12.4 on a Mac OSX, not sure about other setups, sorry...

@Narigo Narigo force-pushed the preserve-timestamps branch from 065a057 to 040e07e Compare June 22, 2015 13:53
@jprichardson
Copy link
Owner

The millisecond precision issue still exists. You can see exactly what I'm talking about here:

It seems that on Windows/Linux Node v0.12 / io.js platform issue? All tests pass on Node v0.10 on every platform. Any ideas?

@jprichardson
Copy link
Owner

Perhaps a Node.js/io.js bug introduced in fs.utimes and fs.utimesSync?

@jprichardson
Copy link
Owner

Ok, so it looks like fs.lstat returned only second precision in Node v0.10, hence why tests are passing. In Node v0.11 (hence 0.12 / io.js), fs.lstat returns millisecond precision and fs.utimes only supports setting second precision. So as I see it, we have two solutions:

  1. Reduce our timestamps to second precision on return from fs.lstat. (Easy: Math.floor(timestamp / 1000) * 1000)
  2. Use fs.futimes. But that would require us to call fs.open and fs.close as well but we have the benefit of maintaining millisecond precision.

My sense is to say that let's keep the code simple, and go with option 1. Does anyone really care that much about millisecond precision? If it becomes an issue, we could always choose option 2 in the future.

What are your thoughts?

@jprichardson
Copy link
Owner

@goloroden what are your thoughts on the two options?

@goloroden
Copy link

Well, the point is that this feature is only useful if the timestamps are exactly the same. Our initial problem was that docker build regarded files as changed even if nothing had changed except the timestamp.

Hence, I'd vote for option 2: Otherwise it's not really preserving the timestamp, but only almost doing so (which in the end is the same as not preserving it at all).

So, I'd vote for option 2 to really be correct (although I have to admit that it's not nice, but at least it's correct).

@jprichardson
Copy link
Owner

@goloroden yeah, good point. @Narigo we could create two methods fs.utimesMillis (sync too) and place them in ./lib/util/, these methods would then do the fs.open, fs.futimes, fs.close craziness. This would help us to keep the fs.copy and fs.copySync code as it now without introducing any additional complexity.

@goloroden
Copy link

@jprichardson Thanks :-)

And @Narigo: Thank you very much for taking the time to fix / implement this :-)!

@Narigo
Copy link
Contributor Author

Narigo commented Jun 22, 2015

@jprichardson can you merge and implement that? :) I won't be able to do it today anymore and am gone for almost a week. Not sure where I can squeeze that in... :(

@Narigo
Copy link
Contributor Author

Narigo commented Jun 22, 2015

@jprichardson are you working on it right now? I've seen your commits for the utimes util file. I'd have about 30 minutes to try and see how far I can get now (sleep's overrated)

@jprichardson
Copy link
Owner

Go for it. I'm probably done for the day on it :) Most of it should be working other than the utimesMillisSync function.

@Narigo Narigo force-pushed the preserve-timestamps branch from 040e07e to be5c6bb Compare June 22, 2015 21:27
@Narigo
Copy link
Contributor Author

Narigo commented Jun 22, 2015

Looks like AppVeyor doesn't like me. Travis works now, though... no time to debug/fix the appveyor part anymore :(

jprichardson added a commit that referenced this pull request Jun 26, 2015
Add option to preserve timestamps
@jprichardson jprichardson merged commit 37f78ca into jprichardson:master Jun 26, 2015
@jprichardson
Copy link
Owner

I've been unable to get this to work on Windows. I believe it to be a bug in Node.js/io.js. Submitted bug report: nodejs/node#2069

@jprichardson jprichardson mentioned this pull request Jun 28, 2015
@Narigo Narigo deleted the preserve-timestamps branch August 1, 2015 17:52
@Mey1212
Copy link

Mey1212 commented Mar 7, 2023

res.on('data', function(chunkBuffer) {
body += chunkBuffer.toString('utf8');
});

Repository owner locked as resolved and limited conversation to collaborators Mar 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Preserve timestamps on copying files
5 participants