Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 64b7791

Browse files
When read returns EOF, ensure future reads still check the file for EOF
Go back to the idle mode when returning EOF, so that the next read will make another attempt to read from the file in case the file grew.
1 parent 955fa65 commit 64b7791

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

‎src/fs/file.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -670,14 +670,19 @@ impl LockGuard<State> {
670670

671671
match self.mode {
672672
Mode::Idle => {}
673+
Mode::Reading(0) if self.cache.is_empty() => {
674+
// If the cache is empty in reading mode, the last operation didn't read any bytes,
675+
// which indicates that it reached the end of the file. In this case we need to
676+
// reset the mode to idle so that next time we try to read again, since the file
677+
// may grow after the first EOF.
678+
self.mode = Mode::Idle;
679+
return Poll::Ready(Ok(0));
680+
}
673681
Mode::Reading(start) => {
674682
// How many bytes in the cache are available for reading.
675683
let available = self.cache.len() - start;
676684

677-
// If there is cached unconsumed data or if the cache is empty, we can read from
678-
// it. Empty cache in reading mode indicates that the last operation didn't read
679-
// any bytes, i.e. it reached the end of the file.
680-
if available > 0 || self.cache.is_empty() {
685+
if available > 0 {
681686
// Copy data from the cache into the buffer.
682687
let n = cmp::min(available, buf.len());
683688
buf[..n].copy_from_slice(&self.cache[start..(start + n)]);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /