Skip to content

Commit 33c89b4

Browse files
committed
Handle ELOOP in File.open call chain.
1 parent 6ea306f commit 33c89b4

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

core/src/main/java/org/jruby/Ruby.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3497,6 +3497,10 @@ public RaiseException newErrnoEINVALError() {
34973497
return newRaiseException(getErrno().getClass("EINVAL"), "Invalid file");
34983498
}
34993499

3500+
public RaiseException newErrnoELOOPError() {
3501+
return newRaiseException(getErrno().getClass("ELOOP"), "Too many levels of symbolic links");
3502+
}
3503+
35003504
public RaiseException newErrnoENOENTError() {
35013505
return newRaiseException(getErrno().getClass("ENOENT"), "File not found");
35023506
}
@@ -3854,6 +3858,8 @@ public RaiseException newIOErrorFromException(IOException e) {
38543858
|| "An existing connection was forcibly closed by the remote host".equals(e.getMessage()) ||
38553859
(Platform.IS_WINDOWS && e.getMessage().contains("connection was aborted"))) {
38563860
return newErrnoECONNRESETError();
3861+
} else if ("Too many levels of symbolic links".equals(e.getMessage())) {
3862+
return newErrnoELOOPError();
38573863
}
38583864
return newRaiseException(getIOError(), e.getMessage());
38593865
} else {

core/src/main/java/org/jruby/util/RegularFileResource.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ public Channel openChannel(ModeFlags flags, int perm) throws ResourceException {
162162
throw new ResourceException.InvalidArguments(absolutePath());
163163
case ENOENT:
164164
throw new ResourceException.NotFound(absolutePath());
165+
case ELOOP:
166+
throw new ResourceException.TooManySymlinks(absolutePath());
165167
default:
166168
throw new ResourceException.IOError(new IOException("unhandled errno: " + errno));
167169

core/src/main/java/org/jruby/util/ResourceException.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
// While it is public, please don't use this, since in master it will be
99
// marked private and replaced by RaisableException usage.
1010
public abstract class ResourceException extends IOException {
11+
public ResourceException() {}
12+
public ResourceException(Throwable t) {
13+
super(t);
14+
}
15+
1116
abstract static class ErrnoException extends ResourceException {
1217
private final String path;
1318
private final String errnoClass;
@@ -43,10 +48,15 @@ public static class InvalidArguments extends ErrnoException {
4348
public InvalidArguments(String path) { super("EINVAL", path); }
4449
}
4550

51+
public static class TooManySymlinks extends ErrnoException {
52+
public TooManySymlinks(String path) { super("ELOOP", path); }
53+
}
54+
4655
public static class IOError extends ResourceException {
4756
private final IOException ioe;
4857

4958
IOError(IOException ioe) {
59+
super(ioe);
5060
this.ioe = ioe;
5161
}
5262

core/src/main/java/org/jruby/util/io/PosixShim.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,10 @@ public Channel open(String cwd, String path, ModeFlags flags, int perm, ClassLoa
412412
errno = Errno.ENOENT;
413413
} catch (ResourceException.PermissionDenied e) {
414414
errno = Errno.EACCES;
415+
} catch (ResourceException.TooManySymlinks e) {
416+
errno = Errno.ELOOP;
415417
} catch (IOException e) {
418+
e.printStackTrace();
416419
throw new RuntimeException("Unhandled IOException", e);
417420
}
418421
return null;

0 commit comments

Comments
 (0)