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: 5a244b844f58
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0411d68db1a9
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Jun 19, 2018

  1. [refactor] decode ruby string once on exist?(path)

    also do 'normal' file checking first instead of class-path scan
    (separate classpath:/ check could be refactored with resources)
    kares committed Jun 19, 2018

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    stepankuzmin Stepan Kuzmin
    Copy the full SHA
    04542a6 View commit details
  2. [refactor] no need to re-create JRubyFile twice

    ... with an absolute-path - for more consistent behavior
    + removed symlink comments that seem no longer relevant
    kares committed Jun 19, 2018

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    stepankuzmin Stepan Kuzmin
    Copy the full SHA
    0411d68 View commit details
Showing with 16 additions and 20 deletions.
  1. +12 −15 core/src/main/java/org/jruby/RubyFileTest.java
  2. +4 −5 core/src/main/java/org/jruby/util/RegularFileResource.java
27 changes: 12 additions & 15 deletions core/src/main/java/org/jruby/RubyFileTest.java
Original file line number Diff line number Diff line change
@@ -125,7 +125,11 @@ public static IRubyObject exist_p(ThreadContext context, IRubyObject recv, IRuby
}

static boolean exist(ThreadContext context, RubyString path) {
return existsOnClasspath(path) || !Ruby.isSecurityRestricted() && fileResource(context, path).exists();
final String pathStr = path.decodeString();
if (!Ruby.isSecurityRestricted()) {
if (JRubyFile.createResource(context.runtime, pathStr).exists()) return true;
}
return existsOnClasspath(context, pathStr);
}

@Deprecated
@@ -473,24 +477,17 @@ private static RubyFileStat getRubyFileStat(ThreadContext context, IRubyObject f
return stat;
}

private static boolean existsOnClasspath(IRubyObject path) {
if (path instanceof RubyFile) {
return false;
}

Ruby runtime = path.getRuntime();
RubyString pathStr = get_path(runtime.getCurrentContext(), path);
String pathJStr = pathStr.getUnicodeValue();
if (pathJStr.startsWith("classpath:/")) {
pathJStr = pathJStr.substring("classpath:/".length());
private static boolean existsOnClasspath(ThreadContext context, String path) {
if (path.startsWith("classpath:/")) {
path = path.substring("classpath:/".length());

ClassLoader classLoader = runtime.getJRubyClassLoader();
ClassLoader classLoader = context.runtime.getJRubyClassLoader();
// handle security-sensitive case
if (Ruby.isSecurityRestricted() && classLoader == null) {
classLoader = runtime.getInstanceConfig().getLoader();
if (classLoader == null && Ruby.isSecurityRestricted()) {
classLoader = context.runtime.getInstanceConfig().getLoader();
}

InputStream is = classLoader.getResourceAsStream(pathJStr);
InputStream is = classLoader.getResourceAsStream(path);
if (is != null) {
try {
is.close();
9 changes: 4 additions & 5 deletions core/src/main/java/org/jruby/util/RegularFileResource.java
Original file line number Diff line number Diff line change
@@ -32,8 +32,9 @@ class RegularFileResource implements FileResource {
private final JRubyFile file;
private final POSIX posix;

RegularFileResource(POSIX posix, File file) {
this(posix, file.getAbsolutePath());
RegularFileResource(POSIX posix, JRubyFile file) {
this.file = file;
this.posix = posix;
}

protected RegularFileResource(POSIX posix, String filename) {
@@ -90,9 +91,7 @@ private BasicFileAttributes readAttributes() throws IOException {

@Override
public boolean exists() {
// MRI behavior: Even broken symlinks should return true.
// FIXME: Where is the above statement true? For RubyFile{,Test} it does not seem to be.
return file.exists(); // || isSymLink();
return file.exists();
}

@Override