Skip to content

Commit

Permalink
Handle ELOOP in File.open call chain.
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Nov 4, 2014
1 parent 6ea306f commit 33c89b4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions core/src/main/java/org/jruby/Ruby.java
Expand Up @@ -3497,6 +3497,10 @@ public RaiseException newErrnoEINVALError() {
return newRaiseException(getErrno().getClass("EINVAL"), "Invalid file");
}

public RaiseException newErrnoELOOPError() {
return newRaiseException(getErrno().getClass("ELOOP"), "Too many levels of symbolic links");
}

public RaiseException newErrnoENOENTError() {
return newRaiseException(getErrno().getClass("ENOENT"), "File not found");
}
Expand Down Expand Up @@ -3854,6 +3858,8 @@ public RaiseException newIOErrorFromException(IOException e) {
|| "An existing connection was forcibly closed by the remote host".equals(e.getMessage()) ||
(Platform.IS_WINDOWS && e.getMessage().contains("connection was aborted"))) {
return newErrnoECONNRESETError();
} else if ("Too many levels of symbolic links".equals(e.getMessage())) {
return newErrnoELOOPError();
}
return newRaiseException(getIOError(), e.getMessage());
} else {
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/org/jruby/util/RegularFileResource.java
Expand Up @@ -162,6 +162,8 @@ public Channel openChannel(ModeFlags flags, int perm) throws ResourceException {
throw new ResourceException.InvalidArguments(absolutePath());
case ENOENT:
throw new ResourceException.NotFound(absolutePath());
case ELOOP:
throw new ResourceException.TooManySymlinks(absolutePath());
default:
throw new ResourceException.IOError(new IOException("unhandled errno: " + errno));

Expand Down
10 changes: 10 additions & 0 deletions core/src/main/java/org/jruby/util/ResourceException.java
Expand Up @@ -8,6 +8,11 @@
// While it is public, please don't use this, since in master it will be
// marked private and replaced by RaisableException usage.
public abstract class ResourceException extends IOException {
public ResourceException() {}
public ResourceException(Throwable t) {
super(t);
}

abstract static class ErrnoException extends ResourceException {
private final String path;
private final String errnoClass;
Expand Down Expand Up @@ -43,10 +48,15 @@ public static class InvalidArguments extends ErrnoException {
public InvalidArguments(String path) { super("EINVAL", path); }
}

public static class TooManySymlinks extends ErrnoException {
public TooManySymlinks(String path) { super("ELOOP", path); }
}

public static class IOError extends ResourceException {
private final IOException ioe;

IOError(IOException ioe) {
super(ioe);
this.ioe = ioe;
}

Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/org/jruby/util/io/PosixShim.java
Expand Up @@ -412,7 +412,10 @@ public Channel open(String cwd, String path, ModeFlags flags, int perm, ClassLoa
errno = Errno.ENOENT;
} catch (ResourceException.PermissionDenied e) {
errno = Errno.EACCES;
} catch (ResourceException.TooManySymlinks e) {
errno = Errno.ELOOP;
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("Unhandled IOException", e);
}
return null;
Expand Down

0 comments on commit 33c89b4

Please sign in to comment.