From: <pj...@us...> - 2007-11-17 00:05:59
|
Revision: 3689 http://jython.svn.sourceforge.net/jython/?rev=3689&view=rev Author: pjenvey Date: 2007-11-16 16:05:57 -0800 (Fri, 16 Nov 2007) Log Message: ----------- o fix PyFile truncate moving the file position if it was larger than the truncated size o avoid FileIO.readall attempting to allocate a negative sized ByteBuffer when the file position > file size fixes test_largefile Modified Paths: -------------- trunk/jython/src/org/python/core/io/FileIO.java trunk/jython/src/org/python/core/io/TextIOBase.java Modified: trunk/jython/src/org/python/core/io/FileIO.java =================================================================== --- trunk/jython/src/org/python/core/io/FileIO.java 2007-11-16 23:08:05 UTC (rev 3688) +++ trunk/jython/src/org/python/core/io/FileIO.java 2007-11-17 00:05:57 UTC (rev 3689) @@ -188,7 +188,7 @@ // the file is growing long toRead; try { - toRead = fileChannel.size() - fileChannel.position(); + toRead = Math.max(0, fileChannel.size() - fileChannel.position()); } catch (IOException ioe) { throw Py.IOError(ioe); } Modified: trunk/jython/src/org/python/core/io/TextIOBase.java =================================================================== --- trunk/jython/src/org/python/core/io/TextIOBase.java 2007-11-16 23:08:05 UTC (rev 3688) +++ trunk/jython/src/org/python/core/io/TextIOBase.java 2007-11-17 00:05:57 UTC (rev 3689) @@ -129,9 +129,16 @@ /** {@inheritDoc} */ public long truncate(long pos) { + long initialPos = tell(); flush(); - seek(pos); - return bufferedIO.truncate(pos); + pos = bufferedIO.truncate(pos); + // FileChannel resets the position to the truncated size if + // the position was larger, whereas Python expects the + // original position + if (initialPos > pos) { + seek(initialPos); + } + return pos; } /** {@inheritDoc} */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |