Commit bc3d1097 authored by Jeremy Hylton's avatar Jeremy Hylton

Provide much simpler version of getSerial().

parent 32f4f31c
...@@ -115,7 +115,7 @@ ...@@ -115,7 +115,7 @@
# may have a back pointer to a version record or to a non-version # may have a back pointer to a version record or to a non-version
# record. # record.
# #
__version__='$Revision: 1.116 $'[11:-2] __version__='$Revision: 1.117 $'[11:-2]
import base64 import base64
from cPickle import Pickler, Unpickler, loads from cPickle import Pickler, Unpickler, loads
...@@ -573,31 +573,6 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -573,31 +573,6 @@ class FileStorage(BaseStorage.BaseStorage,
if plen != z64: return read(U64(plen)), version, nv if plen != z64: return read(U64(plen)), version, nv
return _loadBack(file, oid, read(8))[0], 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): def _load(self, oid, version, _index, file):
try: try:
pos = _index[oid] pos = _index[oid]
...@@ -1045,6 +1020,13 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -1045,6 +1020,13 @@ class FileStorage(BaseStorage.BaseStorage,
else: else:
return '', '' 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): def _getSerial(self, oid, pos):
self._file.seek(pos) self._file.seek(pos)
h = self._file.read(16) h = self._file.read(16)
...@@ -1222,8 +1204,7 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -1222,8 +1204,7 @@ class FileStorage(BaseStorage.BaseStorage,
while pos < tend: while pos < tend:
self._file.seek(pos) self._file.seek(pos)
h = self._file.read(DATA_HDR_LEN) h = self._file.read(DATA_HDR_LEN)
oid, serial, sprev, stloc, vlen, splen = \ oid, serial, sprev, stloc, vlen, splen = struct.unpack(DATA_HDR, h)
struct.unpack(DATA_HDR, h)
if failed(oid): if failed(oid):
del failures[oid] # second chance! del failures[oid] # second chance!
plen = U64(splen) 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