Skip to content

Commit

Permalink
[Truffle] Raise ENOTEMPTY in Dir.rmdir.
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Mar 17, 2015
1 parent 8e3137a commit 0139e27
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Expand Up @@ -9,12 +9,14 @@
*/
package org.jruby.truffle.nodes.core;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyFile;
import org.jruby.truffle.runtime.core.RubyProc;
Expand Down Expand Up @@ -82,8 +84,8 @@ public int delete(RubyString path) {
}

if (!dir.delete()) {
// TODO(CS, 12-Jan-15) handle failure
throw new UnsupportedOperationException();
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().dirNotEmptyError(path.toString(), this));
}

return 0;
Expand Down
Expand Up @@ -123,6 +123,7 @@ public class CoreLibrary {
private final RubyClass edomClass;
private final RubyClass einvalClass;
private final RubyClass enoentClass;
private final RubyClass enotemptyClass;
private final RubyClass encodingConverterClass;
private final RubyClass encodingCompatibilityErrorClass;
private final RubyClass methodClass;
Expand Down Expand Up @@ -230,7 +231,7 @@ public CoreLibrary(RubyContext context) {
edomClass = new RubyClass(context, errnoModule, systemCallErrorClass, "EDOM");
new RubyClass(context, errnoModule, systemCallErrorClass, "EEXIST");
enoentClass = new RubyClass(context, errnoModule, systemCallErrorClass, "ENOENT");
new RubyClass(context, errnoModule, systemCallErrorClass, "ENOTEMPTY");
enotemptyClass = new RubyClass(context, errnoModule, systemCallErrorClass, "ENOTEMPTY");
new RubyClass(context, errnoModule, systemCallErrorClass, "EPERM");
new RubyClass(context, errnoModule, systemCallErrorClass, "EXDEV");
einvalClass = new RubyClass(context, errnoModule, systemCallErrorClass, "EINVAL");
Expand Down Expand Up @@ -862,6 +863,11 @@ public RubyException fileNotFoundError(String fileName, Node currentNode) {
return new RubyException(enoentClass, context.makeString(String.format("No such file or directory - %s", fileName)), RubyCallStack.getBacktrace(currentNode));
}

public RubyException dirNotEmptyError(String path, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
return new RubyException(enotemptyClass, context.makeString(String.format("Directory not empty - %s", path)), RubyCallStack.getBacktrace(currentNode));
}

public RubyException rangeError(int code, RubyEncoding encoding, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
return rangeError(String.format("invalid codepoint %x in %s", code, encoding.getEncoding()), currentNode);
Expand Down

0 comments on commit 0139e27

Please sign in to comment.