Skip to content

Commit

Permalink
[Truffle] Move mkdir into Rubinius, fix some stat stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Apr 17, 2015
1 parent 1d2698f commit b67e232
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 28 deletions.
26 changes: 0 additions & 26 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/DirNodes.java
Expand Up @@ -113,32 +113,6 @@ public boolean exists(RubyString path) {

}

@CoreMethod(names = "mkdir", needsSelf = false, onSingleton = true, required = 1)
public abstract static class MkdirNode extends CoreMethodNode {

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

public MkdirNode(MkdirNode prev) {
super(prev);
}

@Specialization
public int mkdir(RubyString path) {
notDesignedForCompilation();
String dir = path.toString();

if (!new File(dir).mkdir()) {
CompilerDirectives.transferToInterpreterAndInvalidate();
throw new RaiseException(getContext().getCoreLibrary().fileNotFoundError(dir, this));
}

return 0;
}

}

@CoreMethod(names = {"pwd", "getwd"}, onSingleton = true)
public abstract static class PwdNode extends CoreMethodNode {

Expand Down
Expand Up @@ -169,4 +169,22 @@ public int unlink(RubyString path) {

}

@CoreMethod(names = "mkdir", isModuleFunction = true, required = 2)
public abstract static class MkdirNode extends PointerPrimitiveNodes.ReadAddressPrimitiveNode {

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

public MkdirNode(MkdirNode prev) {
super(prev);
}

@Specialization
public int mkdir(RubyString path, int mode) {
return getContext().getRuntime().getPosix().mkdir(path.toString(), mode);
}

}

}
8 changes: 8 additions & 0 deletions truffle/src/main/ruby/core/rubinius/common/dir.rb
Expand Up @@ -28,6 +28,8 @@

class Dir

FFI = Rubinius::FFI

def self.[](*patterns)
if patterns.size == 1
pattern = Rubinius::Type.coerce_to_path(patterns[0])
Expand Down Expand Up @@ -82,4 +84,10 @@ def self.glob_split(pattern)
result << pattern.byteslice(start, pattern.bytesize)
end

def self.mkdir(path, mode = 0777)
error = FFI::Platform::POSIX.mkdir(Rubinius::Type.coerce_to_path(path), mode)
Errno.handle path if error != 0
error
end

end
29 changes: 27 additions & 2 deletions truffle/src/main/ruby/core/rubinius/common/file.rb
Expand Up @@ -338,11 +338,36 @@ def self.fnmatch(pattern, path, flags=0)
brace_match || super(pattern, path, flags)
end

end
##
# Returns a File::Stat object for the named file (see File::Stat).
#
# File.stat("testfile").mtime #=> Tue Apr 08 12:58:04 CDT 2003
def self.stat(path)
Stat.new path
end

File::Stat = Rubinius::Stat
end

# Inject the constants into IO
class IO
include File::Constants
end

File::Stat = Rubinius::Stat
class File::Stat
@module_name = :"File::Stat"

def world_readable?
if mode & S_IROTH == S_IROTH
tmp = mode & (S_IRUGO | S_IWUGO | S_IXUGO)
return Rubinius::Type.coerce_to tmp, Fixnum, :to_int
end
end

def world_writable?
if mode & S_IWOTH == S_IWOTH
tmp = mode & (S_IRUGO | S_IWUGO | S_IXUGO)
return Rubinius::Type.coerce_to tmp, Fixnum, :to_int
end
end
end

0 comments on commit b67e232

Please sign in to comment.