Skip to content

Commit

Permalink
[Truffle] Add File.lchmod
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Fish committed Sep 23, 2016
1 parent 567e3e1 commit 37852c0
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
1 change: 0 additions & 1 deletion spec/truffle/tags/core/file/lchmod_tags.txt
@@ -1,3 +1,2 @@
fails:File.lchmod changes the file mode of the link and not of the file
fails(linux/openbsd, not supposed to impl):File.lchmod returns false from #respond_to?
fails(linux/openbsd, not supposed to impl):File.lchmod raises a NotImplementedError when called
Expand Up @@ -311,6 +311,17 @@ public int setenv(DynamicObject name, DynamicObject value, int overwrite) {

}

@CoreMethod(names = "lchmod", isModuleFunction = true, required = 2, lowerFixnum = 2, unsafe = UnsafeGroup.IO)
public abstract static class LchmodNode extends CoreMethodArrayArgumentsNode {

@CompilerDirectives.TruffleBoundary
@Specialization(guards = "isRubyString(path)")
public int lchmod(DynamicObject path, int mode) {
return posix().lchmod(decodeUTF8(path), mode);
}

}

@CoreMethod(names = "link", isModuleFunction = true, required = 2, unsafe = UnsafeGroup.IO)
public abstract static class LinkNode extends CoreMethodArrayArgumentsNode {

Expand Down
Expand Up @@ -187,6 +187,11 @@ public SignalHandler signal(Signal sig, SignalHandler handler) {
return posix.signal(sig, handler);
}

@Override
public int lchmod(String filename, int mode) {
return posix.lchmod(filename, mode);
}

@Override
public int link(String oldpath, String newpath) {
return posix.link(oldpath, newpath);
Expand Down
Expand Up @@ -54,6 +54,7 @@ public interface TrufflePosix {
boolean isatty(FileDescriptor descriptor);
int kill(int pid, int signal);
int kill(long pid, int signal);
int lchmod(String filename, int mode);
SignalHandler signal(Signal sig, SignalHandler handler);
int link(String oldpath,String newpath);
int lstat(String path, FileStat stat);
Expand Down
1 change: 0 additions & 1 deletion truffle/src/main/ruby/core/file.rb
Expand Up @@ -247,7 +247,6 @@ def self.chmod(mode, *paths)
# the link, not the file referenced by the link).
# Often not available.
def self.lchmod(mode, *paths)
raise NotImplementedError, "lchmod not implemented on this platform" unless Rubinius::HAVE_LCHMOD

This comment has been minimized.

Copy link
@bjfish

bjfish Sep 23, 2016

Contributor

@headius Regarding HAVE_LCHMOD Is there a way to use jnr-posix to tell if a platform defines a function (before calling it)? Or is this something that should be added to jnr-posix? Thanks.

cc: @nirvdrum

This comment has been minimized.

Copy link
@headius

headius Sep 23, 2016

Member

I think that's something we'd need to add.


mode = Rubinius::Type.coerce_to(mode, Integer, :to_int)

Expand Down

0 comments on commit 37852c0

Please sign in to comment.