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

Error in File.stat #2424

Closed
n-nishizawa opened this issue Jan 5, 2015 · 9 comments
Closed

Error in File.stat #2424

n-nishizawa opened this issue Jan 5, 2015 · 9 comments

Comments

@n-nishizawa
Copy link

I'm using jruby 1.7.17

$ jruby -v
jruby 1.7.17 (1.9.3p392) 2014-12-09 fafd1a7 on Java HotSpot(TM) 64-Bit Server VM 1.7.0_07-b10 +jit [Windows 7-amd64]

I tested this code on windows 7.

# coding: utf-8

path = 'てすと.txt'
puts "FileTest.readable?: #{FileTest.readable?(path)}"
puts File.stat(path)

And I got an error when I set java default encoding utf-8.

>jruby -J-Dfile.encoding=utf-8 stat.rb
FileTest.readable?: true
Errno::ENOENT: No such file or directory - 縺ヲ縺吶→.txt
    stat at org/jruby/RubyFile.java:848
  (root) at stat.rb:5

The file specified by the variable path exists.
In fact, FileTest.readable? returns true.
And I can also read data from the file.
But File.stat throws an exception.

@n-nishizawa
Copy link
Author

This is an additional information.
Methods that access file attributes(stat) raise the same error.
For example File.ctime and File.ftype.

  • File.ctime
# coding: utf-8

path = './てすと.txt'
puts "FileTest.readable?: #{FileTest.readable?(path)}"
puts File.ctime(path)
> jruby -J-Dfile.encoding=utf-8 .\stat.rb
FileTest.readable?: true
Errno::ENOENT: No such file or directory - ./縺ヲ縺吶→.txt
   ctime at org/jruby/RubyFile.java:860
  (root) at .\stat.rb:5
  • File.ftype
> jruby -J-Dfile.encoding=utf-8 .\stat.rb
FileTest.readable?: true
Errno::ENOENT: No such file or directory - ./縺ヲ縺吶→.txt
   ftype at org/jruby/RubyFile.java:827
  (root) at .\stat.rb:5

I think handling of the path encoding when accessing the file attributes may be a cause.

@enebo enebo modified the milestones: JRuby 1.7.19, JRuby 1.7.20 Jan 28, 2015
@headius
Copy link
Member

headius commented Feb 23, 2015

Confirmed in JRuby 9k as well. This should be really be fixed for 9k.pre2.

@headius
Copy link
Member

headius commented Feb 23, 2015

Ok, I think I see the problem. We are using _stat64 as our win32 stat call, but we probably should be using _wstat which supports wide characters. There may be a way to make stat64 work properly if we transcode the characters to some appropriate encoding (we we may not be doing by just letting default Java transcoding convert the char[] back to byte[].

I'll see if I can get a jnr-posix change made to add _wstat.

@headius
Copy link
Member

headius commented Feb 23, 2015

Yup, that appears to fix it. We will need to patch and release jnr-posix for this. I will make the change there, but we need a release of it and pom.xml bump for 9k.pre2.

This may also fix it in 1.7, but I did not test that. 1.7 would need the same jnr-posix upgrade treatment.

Tagging @enebo re: jnr-posix lifecycle.

@headius headius modified the milestones: 9.0.0.0.pre2, JRuby 1.7.20 Feb 23, 2015
@headius
Copy link
Member

headius commented Feb 23, 2015

Reopening since it still needs release, and @enebo may want us to explore fixing it in 1.7.20 as well.

@headius headius reopened this Feb 23, 2015
@enebo
Copy link
Member

enebo commented Feb 23, 2015

Yeah definitely. We just need to understand more about our last deployment attempt of jffi or possibly just back off that to get these fixes in under the guise of least risk perhaps.

@headius
Copy link
Member

headius commented Apr 28, 2015

I've got the commit to update 1.7 in my local repo and will push shortly, so let's call this fixed.

@headius headius closed this as completed Apr 28, 2015
@headius headius modified the milestones: JRuby 1.7.20, 9.0.0.0.pre2 Apr 28, 2015
@headius headius self-assigned this Apr 28, 2015
@headius
Copy link
Member

headius commented Apr 28, 2015

Oh all right, let's actually just leave it open until @enebo or I can confirm it on Windows.

@headius headius reopened this Apr 28, 2015
headius added a commit that referenced this issue Apr 28, 2015
@enebo
Copy link
Member

enebo commented Apr 29, 2015

Works on windows with jruby-1_7. Closing.

@enebo enebo closed this as completed Apr 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants