mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-26 01:37:20 +00:00
Added generic callback support
This commit is contained in:
parent
e9ef5de0e8
commit
217da798ab
4 changed files with 20 additions and 12 deletions
|
@ -203,10 +203,12 @@ def extract_item(self, item, dest=None, start_cb=None, restore_attrs=True):
|
||||||
os.makedirs(os.path.dirname(path))
|
os.makedirs(os.path.dirname(path))
|
||||||
# Hard link?
|
# Hard link?
|
||||||
if 'source' in item:
|
if 'source' in item:
|
||||||
|
def link_cb(_, __, item):
|
||||||
source = os.path.join(dest, item['source'])
|
source = os.path.join(dest, item['source'])
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
os.unlink(path)
|
os.unlink(path)
|
||||||
os.link(source, path)
|
os.link(source, path)
|
||||||
|
self.store.add_callback(link_cb, item)
|
||||||
else:
|
else:
|
||||||
def extract_cb(chunk, error, (id, i)):
|
def extract_cb(chunk, error, (id, i)):
|
||||||
if i == 0:
|
if i == 0:
|
||||||
|
|
|
@ -137,8 +137,10 @@ def extract_cb(item):
|
||||||
else:
|
else:
|
||||||
archive.extract_item(item, args.dest, start_cb)
|
archive.extract_item(item, args.dest, start_cb)
|
||||||
if dirs and not item['path'].startswith(dirs[-1]['path']):
|
if dirs and not item['path'].startswith(dirs[-1]['path']):
|
||||||
|
def cb(_, __, item):
|
||||||
# Extract directories twice to make sure mtime is correctly restored
|
# Extract directories twice to make sure mtime is correctly restored
|
||||||
archive.extract_item(dirs.pop(-1), args.dest)
|
archive.extract_item(item, args.dest)
|
||||||
|
store.add_callback(cb, dirs.pop(-1))
|
||||||
store = self.open_store(args.archive)
|
store = self.open_store(args.archive)
|
||||||
key = Key(store)
|
key = Key(store)
|
||||||
manifest = Manifest(store, key)
|
manifest = Manifest(store, key)
|
||||||
|
|
|
@ -125,7 +125,7 @@ def cmd(self, cmd, args, callback=None, callback_data=None):
|
||||||
self.odata.append(msgpack.packb((1, self.msgid, cmd, args)))
|
self.odata.append(msgpack.packb((1, self.msgid, cmd, args)))
|
||||||
self.recursion += 1
|
self.recursion += 1
|
||||||
if callback:
|
if callback:
|
||||||
self.callbacks[self.msgid] = callback, callback_data
|
self.add_callback(callback, callback_data)
|
||||||
if self.recursion > 1:
|
if self.recursion > 1:
|
||||||
self.recursion -= 1
|
self.recursion -= 1
|
||||||
return
|
return
|
||||||
|
@ -146,8 +146,7 @@ def cmd(self, cmd, args, callback=None, callback_data=None):
|
||||||
self.recursion -= 1
|
self.recursion -= 1
|
||||||
return res
|
return res
|
||||||
else:
|
else:
|
||||||
c, d = self.callbacks.pop(msgid, (None, None))
|
for c, d in self.callbacks.pop(msgid, []):
|
||||||
if c:
|
|
||||||
c(res, error, d)
|
c(res, error, d)
|
||||||
elif self.odata and self.channel.send_ready():
|
elif self.odata and self.channel.send_ready():
|
||||||
data = self.odata.pop(0)
|
data = self.odata.pop(0)
|
||||||
|
@ -184,6 +183,9 @@ def put(self, id, data, callback=None, callback_data=None):
|
||||||
def delete(self, id, callback=None, callback_data=None):
|
def delete(self, id, callback=None, callback_data=None):
|
||||||
return self.cmd('delete', (id, ), callback, callback_data)
|
return self.cmd('delete', (id, ), callback, callback_data)
|
||||||
|
|
||||||
|
def add_callback(self, cb, data):
|
||||||
|
self.callbacks.setdefault(self.msgid, []).append((cb, data))
|
||||||
|
|
||||||
def flush_rpc(self, counter=None, backlog=0):
|
def flush_rpc(self, counter=None, backlog=0):
|
||||||
counter = counter or self.notifier.enabled
|
counter = counter or self.notifier.enabled
|
||||||
while counter > backlog:
|
while counter > backlog:
|
||||||
|
@ -199,8 +201,7 @@ def flush_rpc(self, counter=None, backlog=0):
|
||||||
self.unpacker.feed(self.channel.recv(BUFSIZE))
|
self.unpacker.feed(self.channel.recv(BUFSIZE))
|
||||||
for type, msgid, error, res in self.unpacker:
|
for type, msgid, error, res in self.unpacker:
|
||||||
self.notifier.enabled.dec()
|
self.notifier.enabled.dec()
|
||||||
c, d = self.callbacks.pop(msgid, (None, None))
|
for c, d in self.callbacks.pop(msgid, []):
|
||||||
if c:
|
|
||||||
c(res, error, d)
|
c(res, error, d)
|
||||||
if msgid == self.msgid:
|
if msgid == self.msgid:
|
||||||
return
|
return
|
||||||
|
|
|
@ -235,6 +235,9 @@ def delete(self, id):
|
||||||
def flush_rpc(self, *args):
|
def flush_rpc(self, *args):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def add_callback(self, cb, data):
|
||||||
|
cb(None, None, data)
|
||||||
|
|
||||||
|
|
||||||
class LoggedIO(object):
|
class LoggedIO(object):
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue