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

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

merged 2 commits into from Jan 24, 2018


Copy link

@philr philr commented Oct 15, 2017

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

>'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 raises Errno::EACCES instead:

>'C:\\Windows', 'r')
Errno::EACCES: Permission denied - C:\Windows
        from org/jruby/ `initialize'
        from org/jruby/ `open'
        from (irb):1:in `<eval>'
        from org/jruby/ `eval'
        from org/jruby/ `loop'
        from org/jruby/ `catch'
        from org/jruby/ `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 Jan 10, 2018

@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 Jan 10, 2018
Author Contributor

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

On Windows, 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 milestone Jan 16, 2018
@enebo enebo merged commit 73846e9 into jruby:master Jan 24, 2018
1 check failed
1 check failed
continuous-integration/appveyor/pr AppVeyor was unable to build non-mergeable pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants