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

Raise Errno::EISDIR when opening a directory for reading on Windows #4818

Merged
merged 2 commits into from Jan 24, 2018

Conversation

Projects
None yet
3 participants
@philr
Contributor

philr commented Oct 15, 2017

On Windows, MRI 2.0.0 and later raises Errno::EISDIR when attempting to open a directory for reading:

> File.open('C:\\Windows', 'r')
Errno::EISDIR: Is a directory @ rb_sysopen - C:\Windows
        from (irb):1:in `initialize'
        from (irb):1:in `open'
        from (irb):1

However, JRuby 9.1.13.0 raises Errno::EACCES instead:

> File.open('C:\\Windows', 'r')
Errno::EACCES: Permission denied - C:\Windows
        from org/jruby/RubyFile.java:366:in `initialize'
        from org/jruby/RubyIO.java:1154:in `open'
        from (irb):1:in `<eval>'
        from org/jruby/RubyKernel.java:994:in `eval'
        from org/jruby/RubyKernel.java:1292:in `loop'
        from org/jruby/RubyKernel.java:1114:in `catch'
        from org/jruby/RubyKernel.java:1114:in `catch'

This pull request modifies RegularFileResource.openChannel() to throw ResourceException.FileIsDirectory in all cases when opening a directory instead of just for writes.

@@ -218,7 +218,7 @@ public Channel openChannel(ModeFlags flags, int perm) throws ResourceException {
return channel;
}
if (file.isDirectory() && flags.isWritable()) {
if (file.isDirectory()) {

This comment has been minimized.

@enebo

enebo Jan 10, 2018

Member

@philr Should this happen on all platforms and not just windows? Sorry this PR got lost in the cracks.

This comment has been minimized.

@philr

philr Jan 10, 2018

Contributor

@enebo On platforms other than Windows (with both MRI and JRuby), File.open(directory) succeeds and an Errno::EISDIR exception is raised when calling File#read.

On Windows, File.open(directory) raises an exception. MRI raises Errno::EISDIR, but JRuby raises Errno::EACCES.

To replicate the behaviour of MRI, it is just this code that handles Windows in the openChannel() method that needs to be changed.

@enebo enebo added this to the JRuby 9.1.16.0 milestone Jan 16, 2018

@enebo enebo merged commit 73846e9 into jruby:master Jan 24, 2018

1 check failed

continuous-integration/appveyor/pr AppVeyor was unable to build non-mergeable pull request
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment