Commit bc3d1097 authored by Jeremy Hylton's avatar Jeremy Hylton

Provide much simpler version of getSerial().

parent 32f4f31c
......@@ -115,7 +115,7 @@
# may have a back pointer to a version record or to a non-version
# record.
#
__version__='$Revision: 1.116 $'[11:-2]
__version__='$Revision: 1.117 $'[11:-2]
import base64
from cPickle import Pickler, Unpickler, loads
......@@ -573,31 +573,6 @@ class FileStorage(BaseStorage.BaseStorage,
if plen != z64: return read(U64(plen)), version, nv
return _loadBack(file, oid, read(8))[0], version, nv
def getSerial(self, oid):
self._lock_acquire()
try:
pos = self._index[oid]
self._file.seek(pos)
h = self._file.read(34)
_oid = h[:8]
if _oid != oid:
raise CorruptedDataError, h
vlen = unpack(">H", h[-2:])[0]
if vlen:
# If there is a version, find out its name and let
# _load() do all the work. This is less efficient
# than possible, because _load() will load the pickle
# data. Being more efficient is too complicated.
self._file.seek(24, 1) # skip plen, pnv, and pv
version = self._file.read(vlen)
pickledata, serial = self._load(oid, version,
self._index, self._file)
return serial
return h[8:16]
finally:
self._lock_release()
def _load(self, oid, version, _index, file):
try:
pos = _index[oid]
......@@ -1045,6 +1020,13 @@ class FileStorage(BaseStorage.BaseStorage,
else:
return '', ''
def getSerial(self, oid):
self._lock_acquire()
try:
return self._getSerial(oid, self._index[oid])
finally:
self._lock_release()
def _getSerial(self, oid, pos):
self._file.seek(pos)
h = self._file.read(16)
......@@ -1222,8 +1204,7 @@ class FileStorage(BaseStorage.BaseStorage,
while pos < tend:
self._file.seek(pos)
h = self._file.read(DATA_HDR_LEN)
oid, serial, sprev, stloc, vlen, splen = \
struct.unpack(DATA_HDR, h)
oid, serial, sprev, stloc, vlen, splen = struct.unpack(DATA_HDR, h)
if failed(oid):
del failures[oid] # second chance!
plen = U64(splen)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment