➜

This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
标题: py3k: file.truncate() changes the file position
类型: Stage:
Components: Windows Versions: Python 3.0
process
状态: closed Resolution: accepted
Dependencies: 后续:
分配给: 抄送列表: amaury.forgeotdarc, gvanrossum
优先级: normal 关键字: patch

Created on 2007-10-24 22:30 by amaury.forgeotdarc, last changed 2022-04-11 14:56 by admin. This issue is now closed.

文件
文件名 上传时间 Description 编辑
truncate.diff amaury.forgeotdarc, 2007-10-24 22:30
Messages (2)
msg56732 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) 日期: 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) 日期: 2007-10-25 23:23
Looks fine to me.
Committed revision 58658.
历史
日期 用户 动作 参数
2022-04-11 14:56:27admin修改github: 45664
2007-10-25 23:23:49gvanrossum修改状态: open -> closed
resolution: accepted
消息: + msg56763
抄送: + gvanrossum
2007-10-25 03:44:04loewis修改keywords: + patch
2007-10-24 22:30:33amaury.forgeotdarc创建