Skip to content

Commit d8a4c18

Browse files
committed
[Truffle] Add more File and File::Stat.
1 parent 2daa9d3 commit d8a4c18

17 files changed

+74
-59
lines changed
Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1 @@
1-
fails:File::Constants::APPEND is defined
2-
fails:File::Constants::CREAT is defined
3-
fails:File::Constants::EXCL is defined
4-
fails:File::Constants::FNM_SYSCASE is defined
5-
fails:File::Constants::LOCK_EX is defined
6-
fails:File::Constants::LOCK_NB is defined
7-
fails:File::Constants::LOCK_SH is defined
8-
fails:File::Constants::LOCK_UN is defined
9-
fails:File::Constants::NONBLOCK is defined
10-
fails:File::Constants::RDONLY is defined
11-
fails:File::Constants::RDWR is defined
12-
fails:File::Constants::TRUNC is defined
13-
fails:File::Constants::WRONLY is defined
14-
fails:File::Constants::NOCTTY is defined
15-
fails:File::Constants::SYNC is defined
161
fails(windows):File::Constants::BINARY is defined

spec/truffle/tags/core/file/delete_tags.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

spec/truffle/tags/core/file/directory_tags.txt

Lines changed: 0 additions & 8 deletions
This file was deleted.

spec/truffle/tags/core/file/executable_real_tags.txt

Lines changed: 0 additions & 6 deletions
This file was deleted.

spec/truffle/tags/core/file/executable_tags.txt

Lines changed: 0 additions & 6 deletions
This file was deleted.

spec/truffle/tags/core/file/expand_path_tags.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
fails:File.expand_path does not replace multiple '/' at the beginning of the path
2-
fails:File.expand_path raises an ArgumentError if the path is not valid
3-
fails:File.expand_path expands ~ENV['USER'] to the user's home directory
42
fails(windows):File.expand_path expands C:/./dir to C:/dir
53
windows:File.expand_path converts a pathname to an absolute pathname, Ruby-Talk:18512
64
windows:File.expand_path converts a pathname to an absolute pathname, using a complete path
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
fails:File.grpowned? takes non primary groups into account
22
fails(windows):File.grpowned? returns false if the file exist
3-
fails:File.grpowned? returns true if the file exist
4-
fails:File.grpowned? accepts an object that has a #to_path method
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
fails:File.identical? returns true for a file and its link
2-
fails:File.identical? returns false if any of the files doesn't exist
32
fails:File.identical? accepts an object that has a #to_path method
4-
fails:File.identical? raises an ArgumentError if not passed two arguments
5-
fails:File.identical? raises a TypeError if not passed String types
63
fails:File.identical? returns true if both named files are identical

spec/truffle/tags/core/file/initialize_tags.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
fails:File.lstat returns a File::Stat object if the given file exists
22
fails:File.lstat returns a File::Stat object when called on an instance of File
3-
fails:File.lstat returns a File::Stat object with symlink properties for a symlink
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
fails:File.new returns a new File with modus num and permissions
2-
fails:File.new opens the existing file, does not change permissions even when they are specified
31
fails:File.new raises an Errorno::EEXIST if the file exists when create a new file with File::CREAT|File::EXCL
42
fails:File.new raises an Errno::EBADF if the first parameter is an invalid file descriptor

spec/truffle/tags/core/file/open_tags.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
fails:File.open opens the file when passed mode, num and permissions
2-
fails:File.open opens the file when passed mode, num, permissions and block
3-
fails:File.open opens the existing file, does not change permissions even when they are specified
41
fails:File.open raises an Errorno::EEXIST if the file exists when open with File::CREAT|File::EXCL
52
fails:File.open raises an Errno::EACCES when opening non-permitted file
63
fails:File.open raises an Errno::EACCES when opening read-only file

spec/truffle/tags/core/filetest/directory_tags.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
fails:FileTest.identical? returns true for a file and its link
2-
fails:FileTest.identical? returns false if any of the files doesn't exist
32
fails:FileTest.identical? accepts an object that has a #to_path method
4-
fails:FileTest.identical? raises an ArgumentError if not passed two arguments
5-
fails:FileTest.identical? raises a TypeError if not passed String types
63
fails:FileTest.identical? returns true if both named files are identical

spec/truffle/tags/core/filetest/size_tags.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

truffle/src/main/java/org/jruby/truffle/nodes/rubinius/PosixNodes.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,22 @@ public RubyBasicObject memset(RubyBasicObject pointer, int c, long length) {
186186

187187
}
188188

189+
@CoreMethod(names = "link", isModuleFunction = true, required = 2)
190+
public abstract static class LinkNode extends PointerPrimitiveNodes.ReadAddressPrimitiveNode {
191+
192+
public LinkNode(RubyContext context, SourceSection sourceSection) {
193+
super(context, sourceSection);
194+
}
195+
196+
@Specialization
197+
public int link(RubyString path, RubyString other) {
198+
final String pathString = RubyEncoding.decodeUTF8(path.getByteList().getUnsafeBytes(), path.getByteList().getBegin(), path.getByteList().getRealSize());
199+
final String otherString = RubyEncoding.decodeUTF8(other.getByteList().getUnsafeBytes(), other.getByteList().getBegin(), other.getByteList().getRealSize());
200+
return posix().link(pathString, otherString);
201+
}
202+
203+
}
204+
189205
@CoreMethod(names = "unlink", isModuleFunction = true, required = 1)
190206
public abstract static class UnlinkNode extends PointerPrimitiveNodes.ReadAddressPrimitiveNode {
191207

truffle/src/main/java/org/jruby/truffle/nodes/rubinius/StatPrimitiveNodes.java

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,35 @@ public abstract class StatPrimitiveNodes {
2424

2525
public static final HiddenKey STAT_IDENTIFIER = new HiddenKey("stat");
2626

27+
28+
@RubiniusPrimitive(name = "stat_dev")
29+
public static abstract class StatDevPrimitiveNode extends StatReadPrimitiveNode {
30+
31+
public StatDevPrimitiveNode(RubyContext context, SourceSection sourceSection) {
32+
super(context, sourceSection);
33+
}
34+
35+
@Specialization
36+
public long dev(RubyBasicObject rubyStat) {
37+
return getStat(rubyStat).dev();
38+
}
39+
40+
}
41+
42+
@RubiniusPrimitive(name = "stat_ino")
43+
public static abstract class StatInoPrimitiveNode extends StatReadPrimitiveNode {
44+
45+
public StatInoPrimitiveNode(RubyContext context, SourceSection sourceSection) {
46+
super(context, sourceSection);
47+
}
48+
49+
@Specialization
50+
public long ino(RubyBasicObject rubyStat) {
51+
return getStat(rubyStat).ino();
52+
}
53+
54+
}
55+
2756
@RubiniusPrimitive(name = "stat_stat")
2857
public static abstract class StatStatPrimitiveNode extends RubiniusPrimitiveNode {
2958

@@ -54,6 +83,35 @@ public Object stat(RubyBasicObject rubyStat, Object path) {
5483

5584
}
5685

86+
@RubiniusPrimitive(name = "stat_fstat")
87+
public static abstract class StatFStatPrimitiveNode extends RubiniusPrimitiveNode {
88+
89+
@Child private WriteHeadObjectFieldNode writeStatNode;
90+
91+
public StatFStatPrimitiveNode(RubyContext context, SourceSection sourceSection) {
92+
super(context, sourceSection);
93+
writeStatNode = new WriteHeadObjectFieldNode(STAT_IDENTIFIER);
94+
}
95+
96+
@Specialization
97+
public int fstat(RubyBasicObject rubyStat, int fd) {
98+
final FileStat stat = posix().allocateStat();
99+
final int code = posix().fstat(fd, stat);
100+
101+
if (code == 0) {
102+
writeStatNode.execute(rubyStat, stat);
103+
}
104+
105+
return code;
106+
}
107+
108+
@Specialization(guards = "!isRubyString(path)")
109+
public Object stat(RubyBasicObject rubyStat, Object path) {
110+
return null;
111+
}
112+
113+
}
114+
57115
@RubiniusPrimitive(name = "stat_lstat")
58116
public static abstract class StatLStatPrimitiveNode extends RubiniusPrimitiveNode {
59117

0 commit comments

Comments
 (0)