summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-10-26 17:19:33 (GMT)
committerGuido van Rossum <guido@python.org>2007-10-26 17:19:33 (GMT)
commit57233cb3f9d59233711e63034cc1e84360f0da15 (patch)
treeaed14b8894966fc10eb1e848314c1898cb903748 /Lib
parent61ec0d32634eaa43bbe433628607c137d91736de (diff)
downloadcpython-57233cb3f9d59233711e63034cc1e84360f0da15.zip
cpython-57233cb3f9d59233711e63034cc1e84360f0da15.tar.gz
cpython-57233cb3f9d59233711e63034cc1e84360f0da15.tar.bz2
Patch 1330 by Christian Heimes (with some TLC applied by myself).
Move most of the messiness with truncate() on Windows into _fileio.c. Still keep the flush() call in io.py though.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/io.py18
1 files changed, 4 insertions, 14 deletions
diff --git a/Lib/io.py b/Lib/io.py
index b201cb2..c2d803c 100644
--- a/Lib/io.py
+++ b/Lib/io.py
@@ -597,24 +597,14 @@ class _BufferedIOMixin(BufferedIOBase):
return self.raw.tell()
def truncate(self, pos=None):
- # On Windows, the truncate operation changes the current position
- # to the end of the file, which may leave us with desynchronized
- # buffers.
- # Since we promise that truncate() won't change the current position,
- # the easiest thing is to capture current pos now and seek back to
- # it at the end.
-
- initialpos = self.tell()
- if pos is None:
- pos = initialpos
-
# Flush the stream. We're mixing buffered I/O with lower-level I/O,
# and a flush may be necessary to synch both views of the current
# file state.
self.flush()
- newpos = self.raw.truncate(pos)
- self.seek(initialpos)
- return newpos
+
+ if pos is None:
+ pos = self.tell()
+ return self.raw.truncate(pos)
### Flush and close ###