Add msgpack-python >= 0.3 compatibility

This commit is contained in:
Jonas Borgström 2013-05-17 14:30:39 +02:00
parent 49744c0457
commit 1dc1411302
3 changed files with 10 additions and 10 deletions

View File

@ -132,7 +132,7 @@ class Archive(object):
return 'Archive(%r)' % self.name
def iter_items(self, filter=None):
unpacker = msgpack.Unpacker()
unpacker = msgpack.Unpacker(use_list=False)
i = 0
n = 20
while True:
@ -205,7 +205,7 @@ class Archive(object):
self.cache.chunks[id] = count - 1, size, csize
# This function is a bit evil since it abuses the cache to calculate
# the stats. The cache transaction must be rolled back afterwards
unpacker = msgpack.Unpacker()
unpacker = msgpack.Unpacker(use_list=False)
cache.begin_txn()
stats = Statistics()
add(self.id)
@ -319,7 +319,7 @@ class Archive(object):
result(item, True)
def delete(self, cache):
unpacker = msgpack.Unpacker()
unpacker = msgpack.Unpacker(use_list=False)
for id in self.metadata['items']:
unpacker.feed(self.key.decrypt(id, self.store.get(id)))
for item in unpacker:

View File

@ -63,15 +63,15 @@ class Cache(object):
self.files = {}
self._newest_mtime = 0
with open(os.path.join(self.path, 'files'), 'rb') as fd:
u = msgpack.Unpacker()
u = msgpack.Unpacker(use_list=True)
while True:
data = fd.read(64 * 1024)
if not data:
break
u.feed(data)
for hash, item in u:
if item[0] < 10:
self.files[hash] = (item[0] + 1,) + item[1:]
item[0] += 1
self.files[hash] = item
def begin_txn(self):
# Initialize transaction snapshot
@ -94,7 +94,7 @@ class Cache(object):
for item in self.files.iteritems():
# Discard cached files with the newest mtime to avoid
# issues with filesystem snapshots and mtime precision
if item[1][3] < self._newest_mtime:
if item[1][0] < 10 and item[1][3] < self._newest_mtime:
msgpack.pack(item, fd)
self.config.set('cache', 'manifest', self.manifest.id.encode('hex'))
with open(os.path.join(self.path, 'config'), 'w') as fd:
@ -192,7 +192,7 @@ class Cache(object):
if (entry and entry[3] == st.st_mtime
and entry[2] == st.st_size and entry[1] == st.st_ino):
# reset entry age
self.files[path_hash] = (0,) + entry[1:]
self.files[path_hash][0] = 0
return entry[4]
else:
return None

View File

@ -26,7 +26,7 @@ class StoreServer(object):
# Make stdout blocking
fl = fcntl.fcntl(sys.stdout.fileno(), fcntl.F_GETFL)
fcntl.fcntl(sys.stdout.fileno(), fcntl.F_SETFL, fl & ~os.O_NONBLOCK)
unpacker = msgpack.Unpacker()
unpacker = msgpack.Unpacker(use_list=False)
while True:
r, w, es = select.select([sys.stdin], [], [], 10)
if r:
@ -71,7 +71,7 @@ class RemoteStore(object):
self.to_send = ''
self.extra = {}
self.pending = {}
self.unpacker = msgpack.Unpacker()
self.unpacker = msgpack.Unpacker(use_list=False)
self.msgid = 0
self.received_msgid = 0
args = ['ssh', '-p', str(location.port), '%s@%s' % (location.user or getpass.getuser(), location.host), 'darc', 'serve']