[Zope3-checkins] CVS: ZODB4/ZODB - FileStorage.py:1.110.6.4

Jeremy Hylton jeremy@zope.com
Tue, 10 Dec 2002 18:58:19 -0500


Update of /cvs-repository/ZODB4/ZODB
In directory cvs.zope.org:/tmp/cvs-serv9130/ZODB

Modified Files:
      Tag: ZODB4-Q-branch
	FileStorage.py 
Log Message:
A few subtle fixes for 0 vs z64.

Also, use _read_data_header() in a few more places.

For 0 vs z64, there were a couple of places that expected a function
to return None or an 8-byte string and tested the return value for
true/false.  With the Q changes, things now return 0 which is false
instead of "\0\0\0\0\0\0\0\0" which is true.  Fix the callers to test
explicitly for None.




=== ZODB4/ZODB/FileStorage.py 1.110.6.3 => 1.110.6.4 ===
--- ZODB4/ZODB/FileStorage.py:1.110.6.3	Tue Dec 10 17:14:40 2002
+++ ZODB4/ZODB/FileStorage.py	Tue Dec 10 18:58:18 2002
@@ -259,15 +259,10 @@
             if not back:
                 # If the backpointer is 0, the object does not currently exist.
                 raise POSKeyError(oid)
-            self._file.seek(back)
-            h = self._file.read(DATA_HDR_LEN)
-            doid, serial, prev, tloc, vlen, plen = unpack(DATA_HDR, h)
-            if vlen:
-                self._file.read(16)
-                version = self._file.read(vlen)
-            if plen != 0:
-                return self._file.read(plen), serial, back, tloc
-            back = u64(self._file.read(8)) # We got a back pointer!
+            h = self._read_data_header(back)
+            if h.plen:
+                return afile.read(h.plen), h.serial, back, h.tloc
+            back = h.back
 
     def _loadBack(self, oid, back, afile=None):
         data, serial, old, tloc = self._loadBack_impl(oid, back, afile)
@@ -702,16 +697,8 @@
                 pos = self._index[oid]
             except KeyError:
                 raise POSKeyError(oid)
-            file=self._file
-            file.seek(pos)
-            s = file.read(34)
-            doid,serial,prev,tloc,vlen = unpack(">8s8s8s8sH", s)
-            if doid != oid:
-                raise CorruptedDataError(oid, s)
-            if vlen:
-                file.read(24) # skip plen, pnv, and pv
-                return file.read(vlen)
-            return ''
+            h = self._read_data_header(pos, oid)
+            return h.version
         finally: self._lock_release()
 
     def store(self, oid, serial, data, version, transaction):
@@ -726,7 +713,7 @@
             pnv = None
             if old:
                 h = self._read_data_header(old)
-                if h.vlen:
+                if h.version:
                     if version != h.version:
                         raise POSException.VersionLockError(oid, version)
                     pnv = h.pnv
@@ -748,8 +735,9 @@
                 # Link to last record for this version:
                 pv = (self._tvindex.get(version, 0)
                       or self._vindex.get(version, 0))
-                self._write_version_header(self._tfile,
-                                           pnv or old, pv, version)
+                if pnv is None:
+                    pnv = old
+                self._write_version_header(self._tfile, pnv, pv, version)
                 self._tvindex[version] = here
 
             self._tfile.write(data)
@@ -850,8 +838,8 @@
             # happening in a version.
             if version:
                 pnv = self._restore_pnv(oid, old, version, prev_pos)
-                if pnv:
-                    self._tfile.write(pnv)
+                if pnv is not None:
+                    self._tfile.write(p64(pnv))
                 else:
                     self._tfile.write(p64(old))
                 # Link to the last record for this version
@@ -882,39 +870,24 @@
             return None
 
         pnv = None
-
-        # Load the record pointed to be prev
-        self._file.seek(prev)
-        h = self._file.read(DATA_HDR_LEN)
-        doid, x, y, z, vlen, w = unpack(DATA_HDR, h)
-        if doid != oid:
-            raise CorruptedDataError(oid, h)
+        h = self._read_data_header(prev, oid)
         # If the previous record is for a version, it must have
         # a valid pnv.
-        if vlen > 0:
-            pnv = self._file.read(8)
-            pv = self._file.read(8)
-            v = self._file.read(vlen)
+        if h.version:
+            return h.pnv
         elif bp:
             # XXX Not sure the following is always true:
             # The previous record is not for this version, yet we
             # have a backpointer to it.  The current record must
             # be an undo of an abort or commit, so the backpointer
             # must be to a version record with a pnv.
-            self._file.seek(bp)
-            h2 = self._file.read(DATA_HDR_LEN)
-            doid2, x, y, z, vlen2, dl = unpack(DATA_HDR, h2)
-            if oid != doid2:
-                raise CorruptedDataError(oid, h2)
-            if vlen2 > 0:
-                pnv = self._file.read(8)
-                pv = self._file.read(8)
-                v = self._file.read(8)
+            h2 = self._read_data_header(bp, oid)
+            if h2.version:
+                return h2.pnv
             else:
                 warn("restore could not find previous non-version data "
                      "at %d or %d" % (prev, bp))
-
-        return pnv
+                return None
 
     def supportsUndo(self):
         return 1
@@ -2351,7 +2324,6 @@
             if h.plen:
                 data = self._file.read(h.plen)
             else:
-                print h.back
                 if not h.back:
                     # If the backpointer is 0, then this transaction
                     # undoes the object creation.  It either aborts