Skip to content

Commit

Permalink
[Truffle] Add FIle#chmod.
Browse files Browse the repository at this point in the history
  • Loading branch information
bjfish committed Apr 30, 2015
1 parent d34f7e9 commit bd3f182
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 20 deletions.
20 changes: 0 additions & 20 deletions spec/truffle/tags/core/file/chmod_tags.txt
@@ -1,23 +1,3 @@
fails:File#chmod returns 0 if successful
fails:File#chmod always succeeds with any numeric values
fails:File#chmod invokes to_int on non-integer argument
fails:File#chmod with '0222' makes file writable but not readable or executable
fails:File#chmod with '0444' makes file readable but not writable or executable
fails:File#chmod with '0666' makes file readable and writable but not executable
fails:File#chmod with '0111' makes file executable but not readable or writable
fails:File#chmod modifies the permission bits of the files specified
fails:File.chmod returns the number of files modified
fails:File.chmod always succeeds with any numeric values
fails:File.chmod accepts an object that has a #to_path method
fails:File.chmod throws a TypeError if the given path is not coercable into a string
fails:File.chmod raises an error for a non existent path
fails:File.chmod invokes to_int on non-integer argument
fails:File.chmod invokes to_str on non-string file names
fails:File.chmod with '0222' makes file writable but not readable or executable
fails:File.chmod with '0444' makes file readable but not writable or executable
fails:File.chmod with '0666' makes file readable and writable but not executable
fails:File.chmod with '0111' makes file executable but not readable or writable
fails:File.chmod modifies the permission bits of the files specified
fails(windows):File#chmod with '0444' makes file readable and executable but not writable
fails(windows):File#chmod with '0644' makes file readable and writable and also executable
fails(windows):File.chmod with '0444' makes file readable and executable but not writable
Expand Down
Expand Up @@ -15,6 +15,7 @@
import jnr.constants.platform.Errno;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyException;
import org.jruby.truffle.runtime.core.RubyNilClass;
import org.jruby.truffle.runtime.core.RubyString;

/**
Expand Down Expand Up @@ -48,6 +49,23 @@ public RubyException unsupported(RubyString message, int errno) {
}
}

@Specialization(guards = "errno == ENOENT")
public RubyException enoent(RubyNilClass message, int errno) {
return getContext().getCoreLibrary().fileNotFoundError("nil", this);
}

@CompilerDirectives.TruffleBoundary
@Specialization(guards = "errno != ENOENT")
public RubyException unsupported(RubyNilClass message, int errno) {
final Errno errnoObject = Errno.valueOf(errno);

if (errnoObject == null) {
throw new UnsupportedOperationException("errno: " + errno + " nil");
} else {
throw new UnsupportedOperationException("errno: " + errnoObject.name());
}
}

}

}
Expand Up @@ -28,6 +28,34 @@
@CoreClass(name = "Rubinius::FFI::Platform::POSIX")
public abstract class PosixNodes {

@CoreMethod(names = "chmod", isModuleFunction = true, required = 2)
public abstract static class ChmodNode extends CoreMethodArrayArgumentsNode {

public ChmodNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
public int chmod(RubyString path, int mode) {
return posix().chmod(path.toString(), mode);
}

}

@CoreMethod(names = "fchmod", isModuleFunction = true, required = 2)
public abstract static class FchmodNode extends CoreMethodArrayArgumentsNode {

public FchmodNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
public int fchmod(int one, int mode) {
return posix().fchmod(one, mode);
}

}

@CoreMethod(names = "getegid", isModuleFunction = true)
public abstract static class GetEGIDNode extends CoreMethodArrayArgumentsNode {

Expand Down

0 comments on commit bd3f182

Please sign in to comment.