[Zodb-checkins] CVS: Zope3/src/zodb/storage/file - pack.py:1.1.2.6

Jeremy Hylton jeremy at zope.com
Fri Apr 18 13:17:43 EDT 2003


Update of /cvs-repository/Zope3/src/zodb/storage/file
In directory cvs.zope.org:/tmp/cvs-serv20152/file

Modified Files:
      Tag: jeremy-new-pack-branch
	pack.py 
Log Message:
Fix packing of George Bailey events and add test of this case.


=== Zope3/src/zodb/storage/file/pack.py 1.1.2.5 => 1.1.2.6 ===
--- Zope3/src/zodb/storage/file/pack.py:1.1.2.5	Thu Apr 17 19:05:01 2003
+++ Zope3/src/zodb/storage/file/pack.py	Fri Apr 18 12:17:12 2003
@@ -270,6 +270,18 @@
 
         return pos, new_pos
 
+    def fetchBackpointer(self, oid, back):
+        """Return data and refs backpointer `back` to object `oid.
+
+        If `back` is 0 or ultimately resolves to 0, return None
+        and None.  In this case, the transaction undoes the object
+        creation.
+        """
+        if back == 0:
+            return None, None
+        data, refs, serial, tid = self._loadBackTxn(oid, back, False)
+        return data, refs
+
     def copyDataRecords(self, pos, th):
         """Copy any current data records between pos and tend.
 
@@ -303,15 +315,13 @@
             if h.plen:
                 refs = self._file.read(8 * h.nrefs)
                 data = self._file.read(h.plen)
-            elif h.back:
+            else:
                 # If a current record has a backpointer, fetch
                 # refs and data from the backpointer.  We need
                 # to write the data in the new record.
-                data, refs, serial, tid = self._loadBackTxn(h.oid, h.back)
-                refs = "".join(refs)
-            else:
-                data = ""
-                refs = ""
+                data, refs = self.fetchBackpointer(h.oid, h.back)
+                if refs is not None:
+                    refs = "".join(refs)
 
             self.writePackedDataRecord(h, data, refs, new_tpos)
             new_pos = self._tfile.tell()
@@ -321,6 +331,10 @@
     def writePackedDataRecord(self, h, data, refs, new_tpos):
         # Update the header to reflect current information, then write
         # it to the output file.
+        if data is None:
+            data = ""
+        if refs is None:
+            refs = ""
         h.prev = 0
         h.back = 0
         h.plen = len(data)
@@ -366,17 +380,8 @@
                 if h.plen:
                     data = self._file.read(h.plen)
                 else:
-                    if not h.back:
-                        # If the backpointer is 0, then this transaction
-                        # undoes the object creation.  It either aborts
-                        # the version that created the object or undid the
-                        # transaction that created it.  Return None
-                        # for data and refs because the backpointer has
-                        # the real data and refs.
-                        data = None
-                        refs = None
-                    else:
-                        data, refs, nil, nil = self._loadBackTxn(h.oid, h.back)
+                    data, refs = self.fetchBackpointer(h.oid, h.back)
+                    if h.back:
                         prev_txn = self.getTxnFromData(h.oid, h.back)
 
                 self._copier.copy(h.oid, h.serial, data, refs, h.version,




More information about the Zodb-checkins mailing list