Skip to content

Commit 8a5ea5c

Browse files
committed
fix File.readable? when native is disabled
this readable? method now follows the same pattern as writable?, file?, directory? and exists? and uses the respective FileResource directly. fixes #2040 and #1983 Sponsored by Lookout Inc.
1 parent 17c67a6 commit 8a5ea5c

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

core/src/main/java/org/jruby/RubyFileTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,7 @@ public static IRubyObject readable_p(ThreadContext context, IRubyObject recv, IR
197197
filename = get_path(context, filename);
198198
}
199199

200-
FileStat stat = fileResource(filename).stat();
201-
return runtime.newBoolean(stat != null && stat.isReadable());
200+
return runtime.newBoolean(fileResource(filename).canRead());
202201
}
203202

204203
// Not exposed by filetest, but so similiar in nature that it is stored here

test/test_file.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,14 @@ def test_file_query # - file?
484484
assert(result == 'falsefalsetrue')
485485
end
486486

487+
def test_readable_query # - readable?
488+
assert(File.readable?('test/test_file.rb'))
489+
assert(File.readable?('test'))
490+
assert(! File.readable?('test_not'))
491+
result = jruby("-e 'print File.readable?(\"test_not\");print File.readable?(\"test\");print File.readable?(\"test/test_file.rb\")'", 'jruby.native.enabled' => 'false' )
492+
assert(result == 'falsetruetrue')
493+
end
494+
487495
def test_file_exist_query
488496
assert(File.exist?('test'))
489497
assert(! File.exist?('test_not'))

0 commit comments

Comments
 (0)