[issue20082] Misbehavior of BufferedRandom.write with raw file in append mode

2020-08-04 Thread Erik Bray


Change by Erik Bray :


--
pull_requests: +20873
pull_request: https://github.com/python/cpython/pull/21729

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue20082] Misbehavior of BufferedRandom.write with raw file in append mode

2018-03-26 Thread Erik Bray

Erik Bray  added the comment:

I keep forgetting about this (given that it's like 5 years old now).  Let me 
see if I can make a new PR for it...

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue20082] Misbehavior of BufferedRandom.write with raw file in append mode

2018-02-01 Thread Nitish

Change by Nitish :


--
nosy: +nitishch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue20082] Misbehavior of BufferedRandom.write with raw file in append mode

2014-11-18 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
nosy: +benjamin.peterson, hynek, pitrou, serhiy.storchaka, stutzbach
stage:  -> patch review
versions: +Python 2.7, Python 3.4, Python 3.5

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue20082] Misbehavior of BufferedRandom.write with raw file in append mode

2013-12-27 Thread Erik Bray

New submission from Erik Bray:

In #18876 I pointed out the following issue:

BufferedWriter/Random doesn't know the raw file was opened with O_APPEND so the 
writes it shows in the buffer differ from what will actually end up in the 
file.  For example:

>>> f = open('test', 'wb')
>>> f.write(b'testest')
7
>>> f.close()
>>> f = open('test', 'ab+')
>>> f.tell()
7
>>> f.write(b'A')
1
>>> f.seek(0)
0
>>> f.read()
b'testestA'
>>> f.seek(0)
0
>>> f.read(1)
b't'
>>> f.write(b'B')
1
>>> f.seek(0)
0
>>> f.read()
b'tBstestA'
>>> f.flush()
>>> f.seek(0)
0
>>> f.read()
b'testestAB'

In this example, I read 1 byte from the beginning of the file, then write one 
byte.  Because of O_APPEND, the effect of the write() call on the raw file is 
to append, regardless of where BufferedWriter seeks it to first.  But before 
the f.flush() call f.read() just shows what's in the buffer which is not what 
will actually be written to the file.  (Naturally, unbuffered io does not have 
this particular problem.)


Now that #18876 we can test if a file was opened in append mode and correct for 
this.  The attach patch includes a pretty simple solution that manually calls 
buffered_seek at the beginning of bufferedwriter_write if the raw file is in 
append mode.  In doing so it made sense to split buffered_seek into two 
separate functions.

This might be overkill, however.

--
components: IO
files: buffered-append-1.patch
keywords: patch
messages: 207015
nosy: erik.bray
priority: normal
severity: normal
status: open
title: Misbehavior of BufferedRandom.write with raw file in append mode
type: behavior
Added file: http://bugs.python.org/file33282/buffered-append-1.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com