Commit 7991e191 authored by Jim Fulton's avatar Jim Fulton

loadSerial wasn't protected by a lock.

parent e03aa4de
...@@ -184,7 +184,7 @@ ...@@ -184,7 +184,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.37 $'[11:-2] __version__='$Revision: 1.38 $'[11:-2]
import struct, time, os, bpthread, string, base64, sys import struct, time, os, bpthread, string, base64, sys
from struct import pack, unpack from struct import pack, unpack
...@@ -585,32 +585,35 @@ class FileStorage(BaseStorage.BaseStorage): ...@@ -585,32 +585,35 @@ class FileStorage(BaseStorage.BaseStorage):
finally: self._lock_release() finally: self._lock_release()
def loadSerial(self, oid, serial): def loadSerial(self, oid, serial):
_index=self._index self._lock_acquire()
file=self._file try:
seek=file.seek _index=self._index
read=file.read file=self._file
pos=_index[oid] seek=file.seek
while 1: read=file.read
seek(pos) pos=_index[oid]
h=read(42) while 1:
doid,dserial,prev,tloc,vlen,plen = unpack(">8s8s8s8sH8s", h) seek(pos)
if doid != oid: raise CorruptedDataError, h h=read(42)
if dserial == serial: break # Yeee ha! doid,dserial,prev,tloc,vlen,plen = unpack(">8s8s8s8sH8s", h)
# Keep looking for serial if doid != oid: raise CorruptedDataError, h
pos=u64(prev) if dserial == serial: break # Yeee ha!
if not pos: raise KeyError, serial # Keep looking for serial
continue pos=u64(prev)
if not pos: raise KeyError, serial
if vlen: continue
pnv=read(8) # Read location of non-version data
read(8) # skip past version link if vlen:
read(vlen) # skip version pnv=read(8) # Read location of non-version data
read(8) # skip past version link
read(vlen) # skip version
if plen != z64: return read(u64(plen)) if plen != z64: return read(u64(plen))
# We got a backpointer, probably from a commit. # We got a backpointer, probably from a commit.
pnv=read(8) pnv=read(8)
return _loadBack(file, oid, pnv)[0] return _loadBack(file, oid, pnv)[0]
finally: self._lock_release()
def modifiedInVersion(self, oid): def modifiedInVersion(self, oid):
self._lock_acquire() self._lock_acquire()
......
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