changeset 5789:e1e79fab9cca editlogfixes

fix edit-log migration issue with wrong line endings while trying a migration from linux-based 1.5.x wiki to windows-based 1.9.3, i had strange failures at 1.8.9999 step, crashed in .refresh() function while parsing the edit-log. Often this crash happens when edit-log was already damaged before, but in this case it seem due to some offset miscalculation in the MoinMoin.logfile code which was maybe triggered by the migration code converting \n line endings to \r\n. a fresh edit-log created on windows just has \n line endings, so we better use binary mode in the converter when opening the output edit-log. i also fixed another inconsistency in MoinMoin.logfile - when it opens the logfile for output, it used mode 'a', but for reading it is 'rb'. changed to 'ab' for consistency.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 11 Oct 2011 14:27:11 +0200
parents 89882824b375
children 3b7c12c2976c
files MoinMoin/logfile/__init__.py MoinMoin/script/migration/_conv160.py
diffstat 2 files changed, 7 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/logfile/__init__.py	Wed Aug 03 00:07:16 2011 +0200
+++ b/MoinMoin/logfile/__init__.py	Tue Oct 11 14:27:11 2011 +0200
@@ -159,7 +159,7 @@
                     raise
             return self._input
         elif name == "_output":
-            self._output = codecs.open(self.__filename, 'a', config.charset)
+            self._output = codecs.open(self.__filename, 'ab', config.charset)
             return self._output
         else:
             raise AttributeError(name)
--- a/MoinMoin/script/migration/_conv160.py	Wed Aug 03 00:07:16 2011 +0200
+++ b/MoinMoin/script/migration/_conv160.py	Tue Oct 11 14:27:11 2011 +0200
@@ -82,7 +82,7 @@
         data = []
         try:
             lineno = 0
-            f = file(self.fname, 'r')
+            f = file(self.fname, 'r') # read in text mode, so we can iterate over text lines
             for line in f:
                 lineno += 1
                 line = line.replace('\r', '').replace('\n', '')
@@ -107,7 +107,8 @@
         """ write complete event-log to disk """
         print "Writing event-log. Depending on the size of event-log this may take a long time."
         if self.data:
-            f = file(fname, 'w')
+            f = file(fname, 'wb') # write in binary mode, so it stays exactly as we write it, even on windows.
+                                  # the code in MoinMoin.logfile also uses binary mode and writes \n only.
             for timestamp, action, kvdict in self.data:
                 pagename = kvdict.get('pagename')
                 if pagename and ('PAGE', pagename) in self.renames:
@@ -136,7 +137,7 @@
         data = {}
         try:
             lineno = 0
-            f = file(self.fname, 'r')
+            f = file(self.fname, 'r') # read in text mode, so we can iterate over text lines
             for line in f:
                 lineno += 1
                 line = line.replace('\r', '').replace('\n', '')
@@ -164,7 +165,8 @@
         if self.data:
             editlog = self.data.items()
             editlog.sort()
-            f = file(fname, "w")
+            f = file(fname, 'wb') # write in binary mode, so it stays exactly as we write it, even on windows.
+                                  # the code in MoinMoin.logfile also uses binary mode and writes \n only.
             max_rev = 0
             for key, fields in editlog:
                 timestamp, rev, action, pagename, ip, hostname, userid, extra, comment = fields