simonc / memfs

MemFs provides a fake file system that can be used for tests. Strongly inspired by FakeFS.
MIT License
320 stars 27 forks source link

Reset the file position when reopened. #23

Closed jimpo closed 7 years ago

jimpo commented 7 years ago

Fixes https://github.com/simonc/memfs/issues/22.

simonc commented 7 years ago

Hi @jimpo and thanks a lot for this.

I just changed a bit the way File.new works so that you should be able to avoid the begin … rescue block. Would you be so kind to rebase and update this PR, that'd be awesome ☺️

Thanks! :wink:

jimpo commented 7 years ago

@simonc When I remove the rescue spec/memfs/file_spec.rb:2428 fails with an ENOENT error. Should I add the rescue back?

simonc commented 7 years ago

@jimpo no, at that point the entry should be there. If it's not it's an issue. The begin .. rescue treats the symptome, not the disease. I'd like to find why it does this. I'll investigate!

simonc commented 7 years ago

@jimpo OK, as I thought it was a bad spec since File.new should raise if the passed filename is a symlink with an absent target.

I'm gonna fix the spec and then your change should pass with no trouble.

simonc commented 7 years ago

@jimpo the issue is fixed. I would recommand to add a condition to the position reset though.

Since File.new accepts directories and they might not accept pos= I'd use the following code:

if entry.respond_to?(:pos=)
  entry.pos = 0
end

Thanks!

jimpo commented 7 years ago

Thanks for following up on this!

simonc commented 7 years ago

My pleasure ☺️