Open cache/files on demand

This commit is contained in:
Jonas Borgström 2011-07-02 20:39:35 +02:00
parent 785ba396bb
commit 0680c0a24f
1 changed files with 5 additions and 1 deletions

View File

@ -60,8 +60,10 @@ class Cache(object):
self.id = self.config.get('cache', 'store_id').decode('hex')
self.tid = self.config.getint('cache', 'tid')
self.chunks = NSIndex(os.path.join(self.path, 'chunks'))
self.files = {}
def _read_files(self):
with open(os.path.join(self.path, 'files'), 'rb') as fd:
self.files = {}
u = msgpack.Unpacker()
while True:
data = fd.read(64 * 1024)
@ -168,6 +170,8 @@ class Cache(object):
self.chunks[id] = (count - 1, size)
def file_known_and_unchanged(self, path_hash, st):
if not self.files:
self._read_files()
entry = self.files.get(path_hash)
if (entry and entry[3] == st.st_mtime
and entry[2] == st.st_size and entry[1] == st.st_ino):