chmod inside of File block fails to create file #1149

Closed
jkutner opened this Issue Oct 22, 2013 · 7 comments

Projects

None yet

3 participants

@jkutner
Member
jkutner commented Oct 22, 2013

While looking at a CI failure on the rubyzip gem, I found that an error
was generated from a line like this:

File.open("data/generated/empty_chmod640.txt", "w") { |f| f.chmod(0640) }

The error was:

RuntimeError: No such file or directory - data/generated/empty_chmod640.txt

I haven't been able to isolate the issue, but it can easily be reproduced from the rubyzip test suite like so:

$ git clone git@github.com:rubyzip/rubyzip.git
$ cd rubyzip
$ git checkout cb6e628fb27b3785527945068e01fcc3fa8d8654
$ bundle install
$ bundle exec rake
...
  adding: data/file2.txt (deflated 79%)
deleting: data/file2.txt
    zip warning: zip file empty
RuntimeError: No such file or directory - data/generated/empty_chmod640.txt
...

The test suite fails to create it's fixtures because of this line (which is the same as the one shown at the top of the issue):
https://github.com/rubyzip/rubyzip/blob/cb6e628fb27b3785527945068e01fcc3fa8d8654/test/gentestfiles.rb#L96

@headius
Member
headius commented Oct 22, 2013

I remember seeing something reported (and being able to reproduce, I think) where File.new { } was not creating the file on disk. I was unable to figure out why it would happen. It seems to be specific to a certain combination of file flags, but I have not managed to narrow it down.

@headius
Member
headius commented Oct 22, 2013

Tried adding f.flush before the chmod and it doesn't seem to make any difference.

@headius
Member
headius commented Oct 22, 2013

I've investigated why it doesn't create the file but not gotten anywhere. There are a couple cases online where FileOutputStream does not create the specified file automatically, so maybe we're not the only ones seeing this. Unsure how to proceed, since I went down to the native code and the JVM even passes O_CREAT to open/64.

@jkutner
Member
jkutner commented Oct 23, 2013

The workaround isn't bad:

File.open("data/generated/empty_chmod640.txt", "w") { }
File.chmod(0640, "data/generated/empty_chmod640.txt")

So I'm not too worried about it.

@jkutner jkutner referenced this issue in rubyzip/rubyzip Oct 23, 2013
Closed

Failure to create test fixtures on JRuby #104

@enebo
Member
enebo commented Feb 17, 2017

@jkutner @headius I do not see this on MacOS. Is this specific to Linux? On 9k, I know we do some native calls now but even with native disabled I am not seeing an issue.

@jkutner
Member
jkutner commented Feb 17, 2017

@enebo no, this was definitely on MacOS, so maybe it went away.

@enebo enebo added this to the JRuby 9.1.8.0 milestone Feb 17, 2017
@enebo
Member
enebo commented Feb 17, 2017

Well optimistically calling this resolved then!

@enebo enebo closed this Feb 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment