Remove peek concept and fix fuse issue

This commit is contained in:
Jonas Borgström 2014-01-23 22:13:08 +01:00
parent c26d63b5fe
commit d023f2aa64
3 changed files with 16 additions and 15 deletions

View File

@ -29,16 +29,17 @@ class DownloadPipeline:
self.repository = repository
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)
for data in self.fetch_many(ids):
unpacker.feed(data)
items = [decode_dict(item, (b'path', b'source', b'user', b'group')) for item in unpacker]
if filter:
items = [item for item in items if filter(item)]
for item in items:
if b'chunks' in item:
self.repository.preload([c[0] for c in item[b'chunks']])
if preload:
for item in items:
if b'chunks' in item:
self.repository.preload([c[0] for c in item[b'chunks']])
for item in items:
yield item
@ -137,9 +138,9 @@ class Archive:
def __repr__(self):
return 'Archive(%r)' % self.name
def iter_items(self, filter=None):
for item in self.pipeline.unpack_many(self.metadata[b'items'], filter=filter):
yield item, None
def iter_items(self, filter=None, preload=False):
for item in self.pipeline.unpack_many(self.metadata[b'items'], filter=filter, preload=preload):
yield item
def add_item(self, item):
self.items_buffer.add(item)
@ -201,7 +202,7 @@ class Archive:
cache.rollback()
return stats
def extract_item(self, item, restore_attrs=True, peek=None):
def extract_item(self, item, restore_attrs=True):
dest = self.cwd
if item[b'path'].startswith('/') or item[b'path'].startswith('..'):
raise Exception('Path should be relative and local')
@ -288,7 +289,7 @@ class Archive:
elif not symlink:
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']:
start(item)
result(item, True)

View File

@ -166,7 +166,7 @@ class Archiver:
numeric_owner=args.numeric_owner)
patterns = adjust_patterns(args.paths, args.excludes)
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']):
archive.extract_item(dirs.pop(-1))
self.print_verbose(remove_surrogates(item[b'path']))
@ -175,7 +175,7 @@ class Archiver:
dirs.append(item)
archive.extract_item(item, restore_attrs=False)
else:
archive.extract_item(item, peek=peek)
archive.extract_item(item)
except IOError as e:
self.print_error('%s: %s', remove_surrogates(item[b'path']), e)
@ -228,7 +228,7 @@ class Archiver:
if args.src.archive:
tmap = {1: 'p', 2: 'c', 4: 'd', 6: 'b', 0o10: '-', 0o12: 'l', 0o14: 's'}
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, '?')
mode = format_file_mode(item[b'mode'])
size = 0
@ -271,9 +271,9 @@ class Archiver:
else:
self.print_verbose('ERROR')
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:
archive.verify_file(item, start_cb, result_cb, peek=peek)
archive.verify_file(item, start_cb, result_cb)
return self.exit_code
def do_info(self, args):

View File

@ -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()}
# Loop through all archive items and assign inode numbers and
# 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'/')
num_segments = len(segments)
parent = 1