[Zodb-checkins] CVS: ZODB3/ZODB - FileStorage.py:1.112
Jeremy Hylton
jeremy@zope.com
Tue, 5 Nov 2002 16:19:32 -0500
Update of /cvs-repository/ZODB3/ZODB
In directory cvs.zope.org:/tmp/cvs-serv6703
Modified Files:
FileStorage.py
Log Message:
Better fix for George Bailey events.
Also, add sanity checks in _getVersion() and _getSerial().
=== ZODB3/ZODB/FileStorage.py 1.111 => 1.112 ===
--- ZODB3/ZODB/FileStorage.py:1.111 Mon Nov 4 17:01:00 2002
+++ ZODB3/ZODB/FileStorage.py Tue Nov 5 16:19:32 2002
@@ -1045,19 +1045,20 @@
def _getVersion(self, oid, pos):
self._file.seek(pos)
- read=self._file.read
- h=read(DATA_HDR_LEN)
- doid,serial,sprev,stloc,vlen,splen = unpack(DATA_HDR, h)
+ h = self._file.read(DATA_HDR_LEN)
+ doid, serial, sprev, stloc, vlen, splen = unpack(DATA_HDR, h)
assert doid == oid
if vlen:
- h=read(16)
- return read(vlen), h[:8]
+ h = self._file.read(16)
+ return self._file.read(vlen), h[:8]
else:
- return '',''
+ return '', ''
def _getSerial(self, oid, pos):
- self._file.seek(pos+8)
- return self._file.read(8)
+ self._file.seek(pos)
+ h = self._file.read(16)
+ assert oid == h[:8]
+ return h[8:]
def _transactionalUndoRecord(self, oid, pos, serial, pre, version):
"""Get the indo information for a data record
@@ -1069,6 +1070,8 @@
"""
copy=1 # Can we just copy a data pointer
+
+ # First check if it is possible to undo this record.
tpos=self._tindex.get(oid, 0)
ipos=self._index.get(oid, 0)
tipos=tpos or ipos
@@ -1103,10 +1106,13 @@
# LoadBack gave us a key error. Bail.
raise UndoError
- if pre:
- version, snv = self._getVersion(oid, pre)
- else:
- version, snv = '', ''
+ # Return the data that should be written in the undo record.
+ if not pre:
+ # There is no previous revision, because the object creation
+ # is being undone.
+ return '', 0, '', '', ipos
+
+ version, snv = self._getVersion(oid, pre)
if copy:
# we can just copy our previous-record pointer forward
return '', pre, version, snv, ipos
@@ -1265,7 +1271,7 @@
tindex[oid] = here
here += odlen
- pos=pos+dlen
+ pos += dlen
if pos > tend:
raise UndoError, 'non-undoable transaction'
@@ -2142,6 +2148,7 @@
while 1:
old = U64(back)
if not old:
+ # If the backpointer is 0, the object does not currently exist.
raise POSKeyError(oid)
file.seek(old)
h = file.read(DATA_HDR_LEN)