Skip to content

Commit

Permalink
Showing 3 changed files with 12 additions and 4 deletions.
3 changes: 0 additions & 3 deletions spec/truffle/tags/core/file/open_tags.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
fails:File.open raises an Errorno::EEXIST if the file exists when open with File::CREAT|File::EXCL
fails:File.open raises an Errno::EACCES when opening non-permitted file
fails:File.open raises an Errno::EACCES when opening read-only file
fails:File.open opens a file for binary read-write starting at the beginning of the file
fails:File.open raises a SystemCallError if passed an invalid Integer type
fails:File.open with a block does not raise error when file is closed inside the block
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@ public static abstract class ExceptionErrnoErrorPrimitiveNode extends RubiniusPr
protected final int ENOENT = Errno.ENOENT.intValue();
protected final int EBADF = Errno.EBADF.intValue();
protected final int EEXIST = Errno.EEXIST.intValue();
protected final int EACCES = Errno.EACCES.intValue();

public ExceptionErrnoErrorPrimitiveNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
@@ -59,6 +60,11 @@ public RubyException eexist(RubyNilClass message, int errno) {
return getContext().getCoreLibrary().fileExistsError("nil", this);
}

@Specialization(guards = "errno == EACCES")
public RubyException eacces(RubyString message, int errno) {
return getContext().getCoreLibrary().permissionDeniedError(message.toString(), this);
}


@CompilerDirectives.TruffleBoundary
@Specialization(guards = "!isExceptionSupported(errno)")
@@ -85,7 +91,7 @@ public RubyException unsupported(RubyNilClass message, int errno) {
}

public static boolean isExceptionSupported(int errno) {
return Errno.ENOENT.intValue() == errno || Errno.EBADF.intValue() == errno || Errno.EEXIST.intValue() == errno;
return Errno.ENOENT.intValue() == errno || Errno.EBADF.intValue() == errno || Errno.EEXIST.intValue() == errno || Errno.EACCES.intValue() == errno;
}

}
Original file line number Diff line number Diff line change
@@ -951,6 +951,11 @@ public RubyException dirNotEmptyError(String path, Node currentNode) {
return new RubyException(getErrnoClass(Errno.ENOTEMPTY), context.makeString(String.format("Directory not empty - %s", path)), RubyCallStack.getBacktrace(currentNode));
}

public RubyException permissionDeniedError(String path, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
return new RubyException(getErrnoClass(Errno.EACCES), context.makeString(String.format("Permission denied - %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);

0 comments on commit 485de9e

Please sign in to comment.