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
merged 2 commits into from
Jan 24, 2018

Conversation

philr
Copy link
Contributor

@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:

> 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()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants