classification
Title: py3k: file.truncate() changes the file position
Type: Stage:
Components: Windows Versions: Python 3.0
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, gvanrossum
Priority: normal Keywords: patch

Created on 2007-10-24 22:30 by amaury.forgeotdarc, last changed 2007-10-25 23:23 by gvanrossum. This issue is now closed.

Files
File name Uploaded Description Edit
truncate.diff amaury.forgeotdarc, 2007-10-24 22:30
Messages (2)
msg56732 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2007-10-24 22:30
This patch corrects a problem in test_file.py on Windows:
f.truncate() seeks to the truncation point, but does not empty the
buffers. In the test, f.tell() returns -1...

Now we flush the file before, and seek to the initial position after.
The same trick was present in 2.5, in fileobject.c::file_truncate. The
same comments apply as well.

Reviewers needed! Flushing may change the behaviour, but seems more
correct to me (and closer to python2.5). Should we add specific tests
for this?

Also, change the test to be sure to close the file before trying to
remove it (it seems that in a finally: block, the exception still
references all the local variables in the traceback). Otherwise the
previous problem is hidden by a "file locked" error in the finally block.
msg56763 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2007-10-25 23:23
Looks fine to me.
Committed revision 58658.
History
Date User Action Args
2007-10-25 23:23:49gvanrossumsetstatus: open -> closed
resolution: accepted
messages: + msg56763
nosy: + gvanrossum
2007-10-25 03:44:04loewissetkeywords: + patch
2007-10-24 22:30:33amaury.forgeotdarccreate