Skip to content

Commit

Permalink
Showing 2 changed files with 11 additions and 19 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyIO.java
Original file line number Diff line number Diff line change
@@ -2984,7 +2984,7 @@ public IRubyObject read(ThreadContext context, IRubyObject length, IRubyObject s
boolean locked = fptr.lock();
try {
fptr.checkCharReadable(context);
return fptr.readAll(context, 0, str);
return fptr.readAll(context, fptr.remainSize(), str);
} finally {
if (locked) fptr.unlock();
}
28 changes: 10 additions & 18 deletions core/src/main/java/org/jruby/util/io/OpenFile.java
Original file line number Diff line number Diff line change
@@ -2620,28 +2620,20 @@ private void SET_TEXT_MODE() {
}

public int remainSize() {
FileStat st;
int siz = READ_DATA_PENDING_COUNT();
long size;
long pos;

// MRI does all this presumably to read more of the file right away, but
// I believe the logic that uses this is ok with just pending read plus buf size.

// if (fstat(fptr -> fd, & st)==0 && S_ISREG(st.st_mode))
// {
// if (io_fflush(fptr) < 0)
// rb_sys_fail(0);
// pos = lseek(fptr -> fd, 0, SEEK_CUR);
// if (st.st_size >= pos && pos >= 0) {
// siz += st.st_size - pos;
// if (siz > LONG_MAX) {
// rb_raise(rb_eIOError, "file too big for single read");
// }
// }
// }
// else {
if ((size = posix.size(fd)) >= 0 &&
(pos = posix.lseek(fd, 0, PosixShim.SEEK_CUR)) >= 0 &&
size > pos) {
if (siz + (size - pos) > Integer.MAX_VALUE) {
throw runtime.newIOError("file too big for single read");
}
siz += size - pos;
} else {
siz += BUFSIZ;
// }
}
return siz;
}

0 comments on commit e5e7eb9

Please sign in to comment.