From f6473155c9f5e849de641c4bf4169f972757d086 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Borgstr=C3=B6m?= Date: Sun, 28 Feb 2010 21:13:21 +0100 Subject: [PATCH] Various fixes. --- dedupstore/archiver.py | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/dedupstore/archiver.py b/dedupstore/archiver.py index 9c160ca95..8d82d1dfb 100644 --- a/dedupstore/archiver.py +++ b/dedupstore/archiver.py @@ -79,27 +79,35 @@ def add_chunk(self, data): else: size = 0 #print 'seen chunk', hash.encode('hex') - self.chunk_incref(hash) - return hash, size + self.chunk_incref(id) + return id, size def seen_chunk(self, hash): return self.chunkmap.get(hash, 0) > 0 - def chunk_incref(self, hash): - sum = struct.unpack('I', hash[:4])[0] - self.chunkmap.setdefault(hash, 0) + def chunk_incref(self, id): + sum = struct.unpack('I', id[:4])[0] + self.chunkmap.setdefault(id, 0) self.summap.setdefault(sum, 0) - self.chunkmap[hash] += 1 + self.chunkmap[id] += 1 self.summap[sum] += 1 - def chunk_decref(self, hash): - self.summap[struct.unpack('I', hash[:4])[0]] -= 1 - count = self.chunkmap.get(hash, 0) - 1 + def chunk_decref(self, id): + sum = struct.unpack('I', id[:4])[0] + sumcount = self.summap[sum] - 1 + count = self.chunkmap[id] - 1 + assert sumcount >= 0 assert count >= 0 - self.chunkmap[hash] = count - if not count: - print 'deleting chunk: ', hash.encode('hex') - self.store.delete(NS_CHUNKS, hash) + if sumcount: + self.summap[sum] = sumcount + else: + del self.summap[sum] + if count: + self.chunkmap[id] = count + else: + del self.chunkmap[id] + print 'deleting chunk: ', id.encode('hex') + self.store.delete(NS_CHUNKS, id) return count @@ -209,7 +217,7 @@ def process_file(self, path, cache): path = path.lstrip('/\\:') ratio = origsize and compsize * 100 / origsize or 0 print '(%d chunks: %d%%)' % (len(chunks), ratio) - return {'type': 'FILE', 'path': path, 'size': size, 'chunks': chunks} + return {'type': 'FILE', 'path': path, 'size': origsize, 'chunks': chunks} def run(self): parser = OptionParser()