Skip to content

Commit

Permalink
More robust way to detect atomic move failure. Fixes jruby#5415.
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Nov 6, 2018
1 parent 21ed843 commit 7b14404
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions core/src/main/java/org/jruby/runtime/Helpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.net.PortUnreachableException;
import java.nio.channels.ClosedChannelException;
import java.nio.charset.Charset;
import java.nio.file.AtomicMoveNotSupportedException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -175,12 +176,22 @@ public static boolean subtractionOverflowed(long original, long other, long resu
}

public static Errno errnoFromException(Throwable t) {
if (t instanceof ClosedChannelException) {
try {
throw t;
} catch (AtomicMoveNotSupportedException amnse) {
return Errno.EXDEV;
} catch (ClosedChannelException cce) {
return Errno.EBADF;
} catch (PortUnreachableException cce) {
return Errno.ECONNREFUSED;
} catch (Throwable t2) {
// fall through
}

final String errorMessage = t.getMessage();
// TODO: this is kinda gross

// FIXME: This is gross and turns out to be fragile if the host system has localized error messages.
// See https://github.com/jruby/jruby/issues/5415
if (errorMessage != null) {
// All errors to sysread should be SystemCallErrors, but on a closed stream
// Ruby returns an IOError. Java throws same exception for all errors so
Expand Down Expand Up @@ -217,12 +228,6 @@ public static Errno errnoFromException(Throwable t) {
case "Is a directory":
return Errno.EISDIR;
}

if (errorMessage.endsWith("Invalid cross-device link")) {
return Errno.EXDEV;
}
} else if (t instanceof PortUnreachableException) {
return Errno.ECONNREFUSED;
}
return null;
}
Expand Down

0 comments on commit 7b14404

Please sign in to comment.