1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-25 01:06:50 +00:00

Improved remote repository exception handling.

This commit is contained in:
Jonas Borgström 2014-01-23 21:43:20 +01:00
parent b41914aa8f
commit 1ee159a939

View file

@ -44,7 +44,7 @@ def serve(self):
f = getattr(self.repository, method)
res = f(*args)
except Exception as e:
sys.stdout.buffer.write(msgpack.packb((1, msgid, e.__class__.__name__, None)))
sys.stdout.buffer.write(msgpack.packb((1, msgid, e.__class__.__name__, e.args)))
else:
sys.stdout.buffer.write(msgpack.packb((1, msgid, None, res)))
sys.stdout.flush()
@ -70,6 +70,7 @@ def __init__(self, name):
self.name = name
def __init__(self, location, create=False):
self.location = location
self.preload_ids = []
self.msgid = 0
self.to_send = b''
@ -77,7 +78,6 @@ def __init__(self, location, create=False):
self.ignore_responses = set()
self.responses = {}
self.unpacker = msgpack.Unpacker(use_list=False)
self.repository_url = '%s@%s:%s' % (location.user, location.host, location.path)
self.p = None
if location.host == '__testsuite__':
args = [sys.executable, '-m', 'attic.archiver', 'serve']
@ -101,13 +101,7 @@ def __init__(self, location, create=False):
version = self.call('negotiate', 1)
if version != 1:
raise Exception('Server insisted on using unsupported protocol version %d' % version)
try:
self.id = self.call('open', location.path, create)
except self.RPCError as e:
if e.name == b'DoesNotExist':
raise Repository.DoesNotExist(self.repository_url)
elif e.name == b'AlreadyExists':
raise Repository.AlreadyExists(self.repository_url)
self.id = self.call('open', location.path, create)
def __del__(self):
self.close()
@ -132,6 +126,10 @@ def fetch_from_cache(args):
error, res = self.responses.pop(waiting_for[0])
waiting_for.pop(0)
if error:
if error == b'DoesNotExist':
raise Repository.DoesNotExist(self.location.orig)
elif error == b'AlreadyExists':
raise Repository.AlreadyExists(self.location.orig)
raise self.RPCError(error)
else:
yield res
@ -189,13 +187,8 @@ def get(self, id_):
return resp
def get_many(self, ids, is_preloaded=False):
try:
for resp in self.call_many('get', [(id_,) for id_ in ids], is_preloaded=is_preloaded):
yield resp
except self.RPCError as e:
if e.name == b'DoesNotExist':
raise Repository.DoesNotExist(self.repository_url)
raise
for resp in self.call_many('get', [(id_,) for id_ in ids], is_preloaded=is_preloaded):
yield resp
def put(self, id_, data, wait=True):
return self.call('put', id_, data, wait=wait)