Commit 053ca4f9 authored by Jeremy Hylton's avatar Jeremy Hylton

Add a close() method that closes the current file, guaranteeting that

any recent updates are written to the file.

Remove seek() and tell() at the beginning of read_index() because
their results are not used.

Add main() that prints the contents a cache file when executed as a
script.

Add a log call when the cache is being read.
parent f0a3d8ab
......@@ -144,14 +144,18 @@ file 0 and file 1.
"""
__version__ = "$Revision: 1.15 $"[11:-2]
__version__ = "$Revision: 1.16 $"[11:-2]
import os, tempfile
from struct import pack, unpack
from thread import allocate_lock
import zLOG
magic='ZEC0'
def LOG(msg, level=zLOG.BLATHER):
zLOG.LOG("ZEC", level, msg)
class ClientCache:
def __init__(self, storage='', size=20000000, client=None, var=None):
......@@ -210,6 +214,9 @@ class ClientCache:
self._limit=size/2
self._current=current
def close(self):
self._f[self._current].close()
def open(self):
self._acquire()
try:
......@@ -407,19 +414,19 @@ class ClientCache:
self._pos=pos+tlen
def read_index(index, serial, f, current):
LOG("read_index(%s)" % f.name)
seek=f.seek
read=f.read
pos=4
seek(0,2)
size=f.tell()
while 1:
f.seek(pos)
seek(pos)
h=read(27)
if len(h)==27 and h[8] in 'vni':
tlen, vlen, dlen = unpack(">iHi", h[9:19])
else: tlen=-1
else:
break
if tlen <= 0 or vlen < 0 or dlen < 0 or vlen+dlen > tlen:
break
......@@ -454,3 +461,15 @@ def read_index(index, serial, f, current):
except: pass
return pos
def main(files):
for file in files:
print file
index = {}
serial = {}
read_index(index, serial, open(file), 0)
print index.keys()
if __name__ == "__main__":
import sys
main(sys.argv[1:])
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