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

Commits on Dec 10, 2014

  1. fix File.executable? when native is disabled

    use the new canExecute method from the FileResource to answer the question.
    for File#executable_real? use posix if native is available. also added
    tests for executable? as well for executable_real?. fixes #2297
    
    Sponsored by Lookout Inc.
    mkristian committed Dec 10, 2014
    Copy the full SHA
    663fb14 View commit details
  2. Copy the full SHA
    b5ce6b9 View commit details
13 changes: 8 additions & 5 deletions core/src/main/java/org/jruby/RubyFileTest.java
Original file line number Diff line number Diff line change
@@ -97,16 +97,19 @@ public static IRubyObject directory_p(ThreadContext context, IRubyObject filenam

@JRubyMethod(name = "executable?", required = 1, module = true)
public static IRubyObject executable_p(IRubyObject recv, IRubyObject filename) {
FileStat stat = fileResource(filename).stat();

return recv.getRuntime().newBoolean(stat != null && stat.isExecutable());
return recv.getRuntime().newBoolean(fileResource(filename).canExecute());
}

@JRubyMethod(name = "executable_real?", required = 1, module = true)
public static IRubyObject executable_real_p(IRubyObject recv, IRubyObject filename) {
FileStat stat = fileResource(filename).stat();
if (recv.getRuntime().getPosix().isNative()) {
FileStat stat = fileResource(filename).stat();

return recv.getRuntime().newBoolean(stat != null && stat.isExecutableReal());
return recv.getRuntime().newBoolean(stat != null && stat.isExecutableReal());
}
else {
return executable_p(recv, filename);
}
}

public static IRubyObject exist_p(IRubyObject recv, IRubyObject filename) {
5 changes: 5 additions & 0 deletions core/src/main/java/org/jruby/util/AbstractFileResource.java
Original file line number Diff line number Diff line change
@@ -5,6 +5,11 @@

abstract class AbstractFileResource implements FileResource {

@Override
public boolean canExecute() {
return false;
}

@Override
public InputStream inputStream() throws ResourceException {
if (!exists()) {
5 changes: 5 additions & 0 deletions core/src/main/java/org/jruby/util/EmptyFileResource.java
Original file line number Diff line number Diff line change
@@ -42,6 +42,11 @@ public boolean isFile() {
return false;
}

@Override
public boolean canExecute() {
return false;
}

@Override
public boolean canRead() {
return false;
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/util/FileResource.java
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ public interface FileResource {
boolean exists();
boolean isDirectory();
boolean isFile();
boolean canExecute();

long lastModified();
long length();
5 changes: 5 additions & 0 deletions core/src/main/java/org/jruby/util/RegularFileResource.java
Original file line number Diff line number Diff line change
@@ -67,6 +67,11 @@ public boolean exists() {
return file.exists(); // || isSymLink();
}

@Override
public boolean canExecute() {
return file.canExecute();
}

@Override
public boolean isFile() {
return file.isFile();
16 changes: 16 additions & 0 deletions test/test_file.rb
Original file line number Diff line number Diff line change
@@ -492,6 +492,22 @@ def test_readable_query # - readable?
assert(result == 'falsetruetrue')
end

[ :executable?, :executable_real? ].each do |method|
define_method :"test_#{method}_query" do # - executable?/executable_real?
if WINDOWS
exec_file = 'bin/jruby.bat'
else
exec_file = 'bin/jruby.sh'
end
assert(File.send(method, exec_file))
assert(!File.send(method, 'test/test_file.rb'))
assert(File.send(method, 'test'))
assert(!File.send(method, 'test_not'))
result = jruby("-e 'print File.#{method}(\"#{exec_file}\");print File.#{method}(\"test_not\");print File.#{method}(\"test\");print File.#{method}(\"test/test_file.rb\")'", 'jruby.native.enabled' => 'false' )
assert(result == 'truefalsetruefalse')
end
end

def test_file_exist_query
assert(File.exist?('test'))
assert(! File.exist?('test_not'))