Skip to content
Permalink
Browse files
Handle ELOOP in File.open call chain.
  • Loading branch information
headius committed Nov 4, 2014
1 parent 6ea306f commit 33c89b43268217d8871bea0fdae049f65313d106
Showing 4 changed files with 21 additions and 0 deletions.
@@ -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");
}
@@ -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 {
@@ -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));

@@ -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;
@@ -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;
}

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

0 comments on commit 33c89b4

Please sign in to comment.