[Zope3-checkins] CVS: Zope3/lib/python/ZODB - FileStorage.py:1.111

Jeremy Hylton jeremy@zope.com
Fri, 6 Dec 2002 18:09:30 -0500


Update of /cvs-repository/Zope3/lib/python/ZODB
In directory cvs.zope.org:/tmp/cvs-serv18478

Modified Files:
	FileStorage.py 
Log Message:
Fix subtle bug in restore().

The _txn_find() must not stop at the pack boundary when it is called
by restore().  It was originally written for _txn_undo() which isn't
supposed to undo to a transaction across a pack.  But it should be
legal to restore() a transaction with a reference to a data record in
a transaction that was packed.

Fix by adding stop_at_pack flag to _txn_find() and add tests of this
behavior for FileStorage.


=== Zope3/lib/python/ZODB/FileStorage.py 1.110 => 1.111 ===
--- Zope3/lib/python/ZODB/FileStorage.py:1.110	Wed Dec  4 16:41:36 2002
+++ Zope3/lib/python/ZODB/FileStorage.py	Fri Dec  6 18:09:29 2002
@@ -798,7 +798,7 @@
         try:
             prev_pos = 0
             if prev_txn is not None:
-                prev_txn_pos = self._txn_find(prev_txn)
+                prev_txn_pos = self._txn_find(prev_txn, 0)
                 if prev_txn_pos:
                     prev_pos = self._data_find(prev_txn_pos, oid, data)
             old = self._index_get(oid, 0)
@@ -1171,12 +1171,12 @@
         # Find the right transaction to undo and call _txn_undo_write().
         tid = base64.decodestring(transaction_id + '\n')
         assert len(tid) == 8
-        tpos = self._txn_find(tid)
+        tpos = self._txn_find(tid, 1)
         tindex = self._txn_undo_write(tpos)
         self._tindex.update(tindex)
         return tindex.keys()
 
-    def _txn_find(self, tid):
+    def _txn_find(self, tid, stop_at_pack):
         pos = self._pos
         # XXX Why 39?  Only because undoLog() uses it as a boundary.
         while pos > 39:
@@ -1187,9 +1187,10 @@
             _tid = h[:8]
             if _tid == tid:
                 return pos
-            status = h[16] # get the c in 8s8sc
-            if status == 'p' or _tid < self._packt:
-                break
+            if stop_at_pack:
+                # check the status field of the transaction header
+                if h[16] == 'p' or _tid < self._packt:
+                    break
         raise UndoError(None, "Invalid transaction id")
 
     def _txn_undo_write(self, tpos):