From: <no...@so...> - 2001-07-16 10:59:36
|
Bugs item #417665, was opened at 2001-04-20 09:03 You can respond by visiting: http://sourceforge.net/tracker/?func=detail&atid=112867&aid=417665&group_id=12867 >Category: Core Group: None >Status: Closed >Resolution: Fixed Priority: 5 Submitted By: brian zimmer (bzimmer) >Assigned to: Finn Bock (bckfnn) >Summary: open(filename, "a") fails to append Initial Comment: Opening a file in append mode does not append to the file but instead starts to write from index 0 which results in overwriting the existing data. To fix the problem, remove the seek() call in flush() as it is not needed. The diff is below. Also see the attached TestCase to demonstrate the problem (use the unittest.py from CPython 2.1). To run the unittest: $> jython pyfiletest.py Index: org/python/core/PyFile.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyFile.java,v retrieving revision 2.18 diff -u -r2.18 PyFile.java --- org/python/core/PyFile.java 2001/03/13 20:21:27 2.18 +++ org/python/core/PyFile.java 2001/04/20 16:02:40 @@ -455,7 +455,6 @@ } public void flush() throws java.io.IOException { - file.seek(bufferStart); file.write(buffer, 0, dataSize); bufferModified = false; file.getFD().sync(); @@ -463,8 +462,7 @@ public void close() throws java.io.IOException { if (writing && bufferModified) { - file.seek(bufferStart); - file.write(buffer, 0, (int)dataSize); + this.flush(); } file.close(); ---------------------------------------------------------------------- >Comment By: Finn Bock (bckfnn) Date: 2001-07-16 03:59 Message: Logged In: YES user_id=4201 Fixed in PyFile.java: 2.20; The fix only ensure that the filepointer is located at the end right after the open. Some unixes always write at the end of the file regardless of the filepointer but that is *not* the case for jython. ---------------------------------------------------------------------- Comment By: Leonkev (vleonkev) Date: 2001-07-11 05:20 Message: Logged In: YES user_id=266902 When you are in append mode, write some data and flush twice before closing. The result is: duplicated data in file ---------------------------------------------------------------------- Comment By: brian zimmer (bzimmer) Date: 2001-04-25 12:54 Message: Logged In: YES user_id=37674 After some more testing, I don't the patch fixes the problem for all cases. ---------------------------------------------------------------------- You can respond by visiting: http://sourceforge.net/tracker/?func=detail&atid=112867&aid=417665&group_id=12867 |