mirror of https://github.com/borgbackup/borg.git
Remove peek concept and fix fuse issue
This commit is contained in:
parent
c26d63b5fe
commit
d023f2aa64
|
@ -29,16 +29,17 @@ class DownloadPipeline:
|
||||||
self.repository = repository
|
self.repository = repository
|
||||||
self.key = key
|
self.key = key
|
||||||
|
|
||||||
def unpack_many(self, ids, filter=None):
|
def unpack_many(self, ids, filter=None, preload=False):
|
||||||
unpacker = msgpack.Unpacker(use_list=False)
|
unpacker = msgpack.Unpacker(use_list=False)
|
||||||
for data in self.fetch_many(ids):
|
for data in self.fetch_many(ids):
|
||||||
unpacker.feed(data)
|
unpacker.feed(data)
|
||||||
items = [decode_dict(item, (b'path', b'source', b'user', b'group')) for item in unpacker]
|
items = [decode_dict(item, (b'path', b'source', b'user', b'group')) for item in unpacker]
|
||||||
if filter:
|
if filter:
|
||||||
items = [item for item in items if filter(item)]
|
items = [item for item in items if filter(item)]
|
||||||
for item in items:
|
if preload:
|
||||||
if b'chunks' in item:
|
for item in items:
|
||||||
self.repository.preload([c[0] for c in item[b'chunks']])
|
if b'chunks' in item:
|
||||||
|
self.repository.preload([c[0] for c in item[b'chunks']])
|
||||||
for item in items:
|
for item in items:
|
||||||
yield item
|
yield item
|
||||||
|
|
||||||
|
@ -137,9 +138,9 @@ class Archive:
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return 'Archive(%r)' % self.name
|
return 'Archive(%r)' % self.name
|
||||||
|
|
||||||
def iter_items(self, filter=None):
|
def iter_items(self, filter=None, preload=False):
|
||||||
for item in self.pipeline.unpack_many(self.metadata[b'items'], filter=filter):
|
for item in self.pipeline.unpack_many(self.metadata[b'items'], filter=filter, preload=preload):
|
||||||
yield item, None
|
yield item
|
||||||
|
|
||||||
def add_item(self, item):
|
def add_item(self, item):
|
||||||
self.items_buffer.add(item)
|
self.items_buffer.add(item)
|
||||||
|
@ -201,7 +202,7 @@ class Archive:
|
||||||
cache.rollback()
|
cache.rollback()
|
||||||
return stats
|
return stats
|
||||||
|
|
||||||
def extract_item(self, item, restore_attrs=True, peek=None):
|
def extract_item(self, item, restore_attrs=True):
|
||||||
dest = self.cwd
|
dest = self.cwd
|
||||||
if item[b'path'].startswith('/') or item[b'path'].startswith('..'):
|
if item[b'path'].startswith('/') or item[b'path'].startswith('..'):
|
||||||
raise Exception('Path should be relative and local')
|
raise Exception('Path should be relative and local')
|
||||||
|
@ -288,7 +289,7 @@ class Archive:
|
||||||
elif not symlink:
|
elif not symlink:
|
||||||
os.utime(path, (item[b'mtime'] / 10**9, item[b'mtime'] / 10**9))
|
os.utime(path, (item[b'mtime'] / 10**9, item[b'mtime'] / 10**9))
|
||||||
|
|
||||||
def verify_file(self, item, start, result, peek=None):
|
def verify_file(self, item, start, result):
|
||||||
if not item[b'chunks']:
|
if not item[b'chunks']:
|
||||||
start(item)
|
start(item)
|
||||||
result(item, True)
|
result(item, True)
|
||||||
|
|
|
@ -166,7 +166,7 @@ class Archiver:
|
||||||
numeric_owner=args.numeric_owner)
|
numeric_owner=args.numeric_owner)
|
||||||
patterns = adjust_patterns(args.paths, args.excludes)
|
patterns = adjust_patterns(args.paths, args.excludes)
|
||||||
dirs = []
|
dirs = []
|
||||||
for item, peek in archive.iter_items(lambda item: not exclude_path(item[b'path'], patterns)):
|
for item in archive.iter_items(lambda item: not exclude_path(item[b'path'], patterns), preload=True):
|
||||||
while dirs and not item[b'path'].startswith(dirs[-1][b'path']):
|
while dirs and not item[b'path'].startswith(dirs[-1][b'path']):
|
||||||
archive.extract_item(dirs.pop(-1))
|
archive.extract_item(dirs.pop(-1))
|
||||||
self.print_verbose(remove_surrogates(item[b'path']))
|
self.print_verbose(remove_surrogates(item[b'path']))
|
||||||
|
@ -175,7 +175,7 @@ class Archiver:
|
||||||
dirs.append(item)
|
dirs.append(item)
|
||||||
archive.extract_item(item, restore_attrs=False)
|
archive.extract_item(item, restore_attrs=False)
|
||||||
else:
|
else:
|
||||||
archive.extract_item(item, peek=peek)
|
archive.extract_item(item)
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
self.print_error('%s: %s', remove_surrogates(item[b'path']), e)
|
self.print_error('%s: %s', remove_surrogates(item[b'path']), e)
|
||||||
|
|
||||||
|
@ -228,7 +228,7 @@ class Archiver:
|
||||||
if args.src.archive:
|
if args.src.archive:
|
||||||
tmap = {1: 'p', 2: 'c', 4: 'd', 6: 'b', 0o10: '-', 0o12: 'l', 0o14: 's'}
|
tmap = {1: 'p', 2: 'c', 4: 'd', 6: 'b', 0o10: '-', 0o12: 'l', 0o14: 's'}
|
||||||
archive = Archive(repository, key, manifest, args.src.archive)
|
archive = Archive(repository, key, manifest, args.src.archive)
|
||||||
for item, _ in archive.iter_items():
|
for item in archive.iter_items():
|
||||||
type = tmap.get(item[b'mode'] // 4096, '?')
|
type = tmap.get(item[b'mode'] // 4096, '?')
|
||||||
mode = format_file_mode(item[b'mode'])
|
mode = format_file_mode(item[b'mode'])
|
||||||
size = 0
|
size = 0
|
||||||
|
@ -271,9 +271,9 @@ class Archiver:
|
||||||
else:
|
else:
|
||||||
self.print_verbose('ERROR')
|
self.print_verbose('ERROR')
|
||||||
self.print_error('%s: verification failed' % remove_surrogates(item[b'path']))
|
self.print_error('%s: verification failed' % remove_surrogates(item[b'path']))
|
||||||
for item, peek in archive.iter_items(lambda item: not exclude_path(item[b'path'], patterns)):
|
for item in archive.iter_items(lambda item: not exclude_path(item[b'path'], patterns), preload=True):
|
||||||
if stat.S_ISREG(item[b'mode']) and b'chunks' in item:
|
if stat.S_ISREG(item[b'mode']) and b'chunks' in item:
|
||||||
archive.verify_file(item, start_cb, result_cb, peek=peek)
|
archive.verify_file(item, start_cb, result_cb)
|
||||||
return self.exit_code
|
return self.exit_code
|
||||||
|
|
||||||
def do_info(self, args):
|
def do_info(self, args):
|
||||||
|
|
|
@ -24,7 +24,7 @@ class AtticOperations(llfuse.Operations):
|
||||||
default_dir = {b'mode': 0o40755, b'mtime': int(time.time() * 1e9), b'uid': os.getuid(), b'gid': os.getgid()}
|
default_dir = {b'mode': 0o40755, b'mtime': int(time.time() * 1e9), b'uid': os.getuid(), b'gid': os.getgid()}
|
||||||
# Loop through all archive items and assign inode numbers and
|
# Loop through all archive items and assign inode numbers and
|
||||||
# extract hierarchy information
|
# extract hierarchy information
|
||||||
for item, _ in archive.iter_items():
|
for item in archive.iter_items():
|
||||||
segments = os.fsencode(os.path.normpath(item[b'path'])).split(b'/')
|
segments = os.fsencode(os.path.normpath(item[b'path'])).split(b'/')
|
||||||
num_segments = len(segments)
|
num_segments = len(segments)
|
||||||
parent = 1
|
parent = 1
|
||||||
|
|
Loading…
Reference in New Issue