Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: d335c0cbbc4f
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 551caa29182a
Choose a head ref
  • 2 commits
  • 5 files changed
  • 2 contributors

Commits on Oct 19, 2017

  1. Raise Errno::ENOTDIR if the parent of an opened file is not a directory.

    Note that Errno::ENOENT is raised on Windows. This is consistent with
    the MRI implementation.
    philr authored and kares committed Oct 19, 2017
    Copy the full SHA
    e7086e5 View commit details
  2. Copy the full SHA
    551caa2 View commit details
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ cache:
- $HOME/.m2

before_install:
- unset _JAVA_OPTIONS
- rm ~/.m2/settings.xml
- export MAVEN_SKIP_RC=true
- mvn -Xmx32M -v | grep 1.7.0; if [ $? = 0 ]; then export MAVEN_OPTS="-XX:MaxPermSize=180M"; else export MAVEN_OPTS="-XX:MaxMetaspaceSize=180M -XX:CompressedClassSpaceSize=180M"; fi
2 changes: 2 additions & 0 deletions core/src/main/java/org/jruby/util/RegularFileResource.java
Original file line number Diff line number Diff line change
@@ -173,6 +173,8 @@ public Channel openChannel(ModeFlags flags, int perm) throws ResourceException {
throw new ResourceException.TooManySymlinks(absolutePath());
case EISDIR:
throw new ResourceException.FileIsDirectory(absolutePath());
case ENOTDIR:
throw new ResourceException.FileIsNotDirectory(absolutePath());
default:
throw new ResourceException.IOError(new IOException("unhandled errno: " + errno));

4 changes: 4 additions & 0 deletions core/src/main/java/org/jruby/util/ResourceException.java
Original file line number Diff line number Diff line change
@@ -32,6 +32,10 @@ public static class FileIsDirectory extends ErrnoException {
public FileIsDirectory(String path) { super("EISDIR", path); }
}

public static class FileIsNotDirectory extends ErrnoException {
public FileIsNotDirectory(String path) { super ("ENOTDIR", path); }
}

public static class FileExists extends ErrnoException {
public FileExists(String path) { super("EEXIST", path); }
}
2 changes: 2 additions & 0 deletions core/src/main/java/org/jruby/util/io/PosixShim.java
Original file line number Diff line number Diff line change
@@ -416,6 +416,8 @@ public Channel open(String cwd, String path, ModeFlags flags, int perm) {
errno = Errno.EEXIST;
} catch (ResourceException.FileIsDirectory e) {
errno = Errno.EISDIR;
} catch (ResourceException.FileIsNotDirectory e) {
errno = Errno.ENOTDIR;
} catch (ResourceException.NotFound e) {
errno = Errno.ENOENT;
} catch (ResourceException.PermissionDenied e) {
5 changes: 5 additions & 0 deletions test/jruby/test_io.rb
Original file line number Diff line number Diff line change
@@ -205,6 +205,11 @@ def test_open_with_block
assert_raises(Errno::EBADF) { f.close }
end

def test_open_child_of_file
ensure_files @file
assert_raises(WINDOWS ? Errno::ENOENT : Errno::ENOTDIR) { File.open(File.join(@file, 'child')) }
end

unless WINDOWS # Windows doesn't take kindly to perm mode tests
def test_sysopen
ensure_files @file