Permalink
Browse files

Merge pull request #472 from atambo/file_size

File.size should handle IO's
  • Loading branch information...
headius committed Mar 22, 2013
2 parents ff74833 + 90981d9 commit a64079496d59c0599879f88a67e774aad0b70172
@@ -1,4 +1,2 @@
fails(JRUBY-4667):File.size? accepts a String-like (to_str) parameter
fails(JRUBY-4667):File.size accepts a String-like (to_str) parameter
-fails:File.size? calls #to_io to convert the argument to an IO
-fails:File.size calls #to_io to convert the argument to an IO
@@ -2,5 +2,3 @@ windows(JRUBY-4820):File#size returns the file's size as a Fixnum
windows(JRUBY-4820):File#size returns the file's size in bytes
windows(JRUBY-4820):File#size returns the file's current size even if modified
windows(JRUBY-4820):File#size for an empty file returns 0
-fails:File.size? calls #to_io to convert the argument to an IO
-fails:File.size calls #to_io to convert the argument to an IO
@@ -280,7 +280,11 @@ public static IRubyObject size(IRubyObject recv, IRubyObject filename) {
public static IRubyObject size(ThreadContext context, IRubyObject recv, IRubyObject filename) {
Ruby runtime = recv.getRuntime();
if (!(filename instanceof RubyFile)) {
- filename = get_path(context, filename);
+ if (filename.respondsTo("to_io")) {
+ filename = (RubyIO) TypeConverter.convertToType(filename, runtime.getIO(), "to_io");
+ } else {
+ filename = get_path(context, filename);
+ }
}
ZipEntry entry = file_in_archive(filename);
@@ -305,7 +309,11 @@ public static IRubyObject size_p(IRubyObject recv, IRubyObject filename) {
public static IRubyObject size_p(ThreadContext context, IRubyObject recv, IRubyObject filename) {
Ruby runtime = context.runtime;
if (!(filename instanceof RubyFile)) {
- filename = get_path(context, filename);
+ if (filename.respondsTo("to_io")) {
+ filename = (RubyIO) TypeConverter.convertToType(filename, runtime.getIO(), "to_io");
+ } else {
+ filename = get_path(context, filename);
+ }
}
ZipEntry entry = file_in_archive(filename);

0 comments on commit a640794

Please sign in to comment.