mirror of
https://github.com/python/cpython.git
synced 2025-10-04 22:20:46 +00:00
Issue #7640: In the new io
module, fix relative seek() for buffered
readable streams when the internal buffer isn't empty. Patch by Pascal Chambon.
This commit is contained in:
parent
6f1cfc1c12
commit
c400610321
3 changed files with 24 additions and 1 deletions
|
@ -1199,6 +1199,10 @@ class BufferedRandom(BufferedWriter, BufferedReader):
|
|||
self.flush()
|
||||
# First do the raw seek, then empty the read buffer, so that
|
||||
# if the raw seek fails, we don't lose buffered data forever.
|
||||
if self._read_buf and whence == 1:
|
||||
# Undo read ahead.
|
||||
with self._read_lock:
|
||||
self.raw.seek(self._read_pos - len(self._read_buf), 1)
|
||||
pos = self.raw.seek(pos, whence)
|
||||
with self._read_lock:
|
||||
self._reset_read_buf()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue