Skip to content

Commit

Permalink
[Truffle] Correct exception when reading as a dir something that is n…
Browse files Browse the repository at this point in the history
…ot a dir.
  • Loading branch information
chrisseaton committed Apr 22, 2015
1 parent 314295c commit cf3bae6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Expand Up @@ -14,6 +14,7 @@
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import com.oracle.truffle.api.object.HiddenKey;
import com.oracle.truffle.api.source.SourceSection;
import jnr.constants.platform.Errno;
import org.jruby.truffle.nodes.objectstorage.ReadHeadObjectFieldNode;
import org.jruby.truffle.nodes.objectstorage.WriteHeadObjectFieldNode;
import org.jruby.truffle.runtime.RubyCallStack;
Expand Down Expand Up @@ -69,10 +70,18 @@ public DirOpenPrimitiveNode(DirOpenPrimitiveNode prev) {
@CompilerDirectives.TruffleBoundary
@Specialization
public RubyNilClass open(RubyBasicObject dir, RubyString path, RubyNilClass encoding) {
final String[] contents = new File(path.toString()).list();
// TODO CS 22-Apr-15 race conditions here

final File file = new File(path.toString());

if (!file.isDirectory()) {
throw new RaiseException(getContext().getCoreLibrary().errnoError(Errno.ENOTDIR.intValue(), this));
}

final String[] contents = file.list();

if (contents == null) {
throw new RaiseException(getContext().getCoreLibrary().fileNotFoundError(path.toString(), this));
throw new UnsupportedOperationException();
}

writeContentsNode.execute(dir, contents);
Expand Down
Expand Up @@ -702,8 +702,7 @@ public RubyException errnoError(int errno, Node currentNode) {
return systemCallError(String.format("Unknown Error (%s)", errno), currentNode);
}

// TODO (nirvdrum 03-Apr-15): This should return the correct errno exception class.
return systemCallError(errnoObj.description(), currentNode);
return new RubyException(getErrnoClass(errnoObj), context.makeString(errnoObj.description()), RubyCallStack.getBacktrace(currentNode));
}

public RubyException indexError(String message, Node currentNode) {
Expand Down

0 comments on commit cf3bae6

Please sign in to comment.