Commit e0c1b0af authored by Jim Fulton's avatar Jim Fulton

untabified.

parent 60171b9d
...@@ -149,7 +149,7 @@ Also, the object ids time stamps are big-endian, so comparisons ...@@ -149,7 +149,7 @@ Also, the object ids time stamps are big-endian, so comparisons
are meaningful. are meaningful.
""" """
__version__='$Revision: 1.8 $'[11:-2] __version__='$Revision: 1.9 $'[11:-2]
import struct, time, os, bpthread, string, base64 import struct, time, os, bpthread, string, base64
now=time.time now=time.time
...@@ -598,83 +598,83 @@ class FileStorage: ...@@ -598,83 +598,83 @@ class FileStorage:
def undo(self, transaction_id): def undo(self, transaction_id):
self._a() self._a()
try: try:
file=self._file file=self._file
seek=file.seek seek=file.seek
read=file.read read=file.read
indexpos=self._indexpos indexpos=self._indexpos
unpack=struct.unpack unpack=struct.unpack
transaction_id=base64.decodestring(transaction_id+'==\n') transaction_id=base64.decodestring(transaction_id+'==\n')
tid, tpos = transaction_id[:8], u64(transaction_id[8:]) tid, tpos = transaction_id[:8], u64(transaction_id[8:])
seek(tpos) seek(tpos)
h=read(23) h=read(23)
if len(h) != 23 or h[:8] != tid: if len(h) != 23 or h[:8] != tid:
raise UndoError, 'Invalid undo transaction id' raise UndoError, 'Invalid undo transaction id'
if h[16] == 'u': return if h[16] == 'u': return
if h[16] != ' ': raise UndoError, 'Undoable transaction' if h[16] != ' ': raise UndoError, 'Undoable transaction'
tl=u64(h[8:16]) tl=u64(h[8:16])
ul,dl,el=unpack(">HHH", h[17:23]) ul,dl,el=unpack(">HHH", h[17:23])
tend=tpos+tl tend=tpos+tl
pos=tpos+23+ul+dl+el pos=tpos+23+ul+dl+el
t=[] t=[]
tappend=t.append tappend=t.append
while pos < tend: while pos < tend:
# Read the data records for this transaction # Read the data records for this transaction
seek(pos) seek(pos)
h=read(42) h=read(42)
oid,serial,sprev,stloc,vlen,splen = unpack(">8s8s8s8sH8s", h) oid,serial,sprev,stloc,vlen,splen = unpack(">8s8s8s8sH8s", h)
plen=u64(splen) plen=u64(splen)
prev=u64(sprev) prev=u64(sprev)
dlen=42+(plen or 8) dlen=42+(plen or 8)
if vlen: dlen=dlen+16+vlen if vlen: dlen=dlen+16+vlen
if indexpos(oid,0) != pos: if indexpos(oid,0) != pos:
raise UndoError, 'Undoable transaction' raise UndoError, 'Undoable transaction'
pos=pos+dlen pos=pos+dlen
if pos > tend: raise UndoError, 'Undoable transaction' if pos > tend: raise UndoError, 'Undoable transaction'
tappend((oid,prev)) tappend((oid,prev))
seek(tpos+16) seek(tpos+16)
file.write('u') file.write('u')
index=self._index index=self._index
for oid, pos in t: index[oid]=pos for oid, pos in t: index[oid]=pos
finally: self._r() finally: self._r()
def undoLog(self, first, last, filter=None): def undoLog(self, first, last, filter=None):
self._a() self._a()
try: try:
pos=self._pos pos=self._pos
if pos < 39: return [] if pos < 39: return []
file=self._file file=self._file
seek=file.seek seek=file.seek
read=file.read read=file.read
unpack=struct.unpack unpack=struct.unpack
strip=string.strip strip=string.strip
encode=base64.encodestring encode=base64.encodestring
r=[] r=[]
append=r.append append=r.append
i=0 i=0
while i < last and pos > 39: while i < last and pos > 39:
seek(pos-8) seek(pos-8)
pos=pos-u64(read(8))-8 pos=pos-u64(read(8))-8
if i < first: continue if i < first: continue
seek(pos) seek(pos)
h=read(23) h=read(23)
tid, tl, status, ul, dl, el = unpack(">8s8scHHH", h) tid, tl, status, ul, dl, el = unpack(">8s8scHHH", h)
if status != ' ': continue if status != ' ': continue
u=ul and read(ul) or '' u=ul and read(ul) or ''
d=dl and read(dl) or '' d=dl and read(dl) or ''
d={'id': encode(tid+p64(pos))[:22], d={'id': encode(tid+p64(pos))[:22],
'time': TimeStamp(tid).timeTime(), 'time': TimeStamp(tid).timeTime(),
'user_name': u, 'description': d} 'user_name': u, 'description': d}
if el: if el:
try: try:
e=loads(read(el)) e=loads(read(el))
d.update(e) d.update(e)
except: pass except: pass
if filter is None or filter(d): if filter is None or filter(d):
append(d) append(d)
i=i+1 i=i+1
return r return r
finally: self._r() finally: self._r()
def versionEmpty(self, version): def versionEmpty(self, version):
......
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