Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 9d8cf7f263a6
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: dbdd06ad2e76
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Jan 3, 2015

  1. Copy the full SHA
    b6a6cba View commit details
  2. Copy the full SHA
    dbdd06a View commit details
Showing with 36 additions and 2 deletions.
  1. +36 −1 core/src/main/java/org/jruby/truffle/nodes/core/FileNodes.java
  2. +0 −1 spec/truffle/tags/core/file/symlink_tags.txt
37 changes: 36 additions & 1 deletion core/src/main/java/org/jruby/truffle/nodes/core/FileNodes.java
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@
import com.oracle.truffle.api.dsl.*;
import com.oracle.truffle.api.frame.*;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import jnr.posix.FileStat;
import org.jruby.truffle.runtime.*;
import org.jruby.truffle.runtime.core.*;
import org.jruby.truffle.runtime.core.RubyArray;
@@ -87,7 +88,7 @@ public int delete(RubyString file) {

}

@CoreMethod(names = "directory?", onSingleton = true, optional = 1)
@CoreMethod(names = "directory?", onSingleton = true, required = 1)
public abstract static class DirectoryNode extends CoreMethodNode {

public DirectoryNode(RubyContext context, SourceSection sourceSection) {
@@ -442,6 +443,40 @@ public Object read(RubyString file) {

}

@CoreMethod(names = "symlink?", onSingleton = true, required = 1)
public abstract static class SymlinkQueryNode extends CoreMethodNode {

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

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

@Specialization
public boolean symlinkQuery(RubyString fileName) {
notDesignedForCompilation();

try {
// Note: We can't use file.exists() to check whether the symlink
// exists or not, because that method returns false for existing
// but broken symlink. So, we try without the existence check,
// but in the try-catch block.
// MRI behavior: symlink? on broken symlink should return true.
FileStat stat = getContext().getRuntime().getPosix().allocateStat();

if (getContext().getRuntime().getPosix().lstat(fileName.toString(), stat) < 0) {
stat = null;
}

return (stat != null && stat.isSymlink());
} catch (SecurityException re) {
return false;
}
}
}

@CoreMethod(names = "write", required = 1)
public abstract static class WriteNode extends CoreMethodNode {

1 change: 0 additions & 1 deletion spec/truffle/tags/core/file/symlink_tags.txt
Original file line number Diff line number Diff line change
@@ -6,4 +6,3 @@ fails:File.symlink raises an ArgumentError if not called with two arguments
fails:File.symlink raises a TypeError if not called with String types
fails:File.symlink? returns true if the file is a link
fails:File.symlink? accepts an object that has a #to_path method
fails:File.symlink? returns false if the file does not exist