From 4679b0dfccd010815d63329c8ee588cad2d57abc Mon Sep 17 00:00:00 2001 From: yackob03 Date: Fri, 18 Oct 2013 20:19:05 -0400 Subject: [PATCH] Fix bugs and clean up data in the way diffs are generated. --- endpoints/registry.py | 10 ++++++---- util/changes.py | 15 ++++++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/endpoints/registry.py b/endpoints/registry.py index c7b22a487..cb219eadd 100644 --- a/endpoints/registry.py +++ b/endpoints/registry.py @@ -339,9 +339,12 @@ def process_image_changes(namespace, repository, image_id): image_diffs_path = store.image_file_diffs_path(namespace, repository, image_id) + image_trie_path = store.image_file_trie_path(namespace, repository, + image_id) + if store.exists(image_diffs_path): logger.debug('Diffs already exist for image: %s' % image_id) - return + return image_trie_path image = model.get_image_by_id(namespace, repository, image_id) parents = model.get_parent_images(image) @@ -370,8 +373,7 @@ def process_image_changes(namespace, repository, image_id): (new_trie, added, changed, removed) = new_metadata # Write out the new trie - new_trie_path = store.image_file_trie_path(namespace, repository, image_id) - store.put_content(new_trie_path, new_trie.tobytes()) + store.put_content(image_trie_path, new_trie.tobytes()) # Write out the diffs diffs = {} @@ -381,4 +383,4 @@ def process_image_changes(namespace, repository, image_id): diffs[section].sort() store.put_content(image_diffs_path, json.dumps(diffs, indent=2)) - return new_trie_path + return image_trie_path diff --git a/util/changes.py b/util/changes.py index 71a82e5e7..814359470 100644 --- a/util/changes.py +++ b/util/changes.py @@ -8,26 +8,31 @@ AUFS_METADATA = u'.wh..wh.' AUFS_WHITEOUT = u'.wh.' AUFS_WHITEOUT_PREFIX_LENGTH = len(AUFS_WHITEOUT) +ALLOWED_TYPES = {tarfile.REGTYPE, tarfile.AREGTYPE} + def files_and_dirs_from_tar(source_stream, removed_prefix_collector): tar_stream = tarfile.open(mode='r|*', fileobj=source_stream) for tar_info in tar_stream: - absolute = os.path.relpath(unicode(tar_info.name), './') + absolute = os.path.relpath(tar_info.name.decode('utf-8'), './') + dirname = os.path.dirname(absolute) filename = os.path.basename(absolute) + # Skip directories and metadata if (filename.startswith(AUFS_METADATA) or absolute.startswith(AUFS_METADATA)): # Skip continue elif filename.startswith(AUFS_WHITEOUT): - filename = filename[AUFS_WHITEOUT_PREFIX_LENGTH:] - removed_prefix_collector.add(absolute) + removed_filename = filename[AUFS_WHITEOUT_PREFIX_LENGTH:] + removed_prefix = os.path.join('/', dirname, removed_filename) + removed_prefix_collector.add(removed_prefix) continue - else: - yield "/" + absolute + elif tar_info.type in ALLOWED_TYPES: + yield '/' + absolute def __compute_removed(base_trie, removed_prefixes):