Fix bugs and clean up data in the way diffs are generated.
This commit is contained in:
parent
6bebfcc3a1
commit
4679b0dfcc
2 changed files with 16 additions and 9 deletions
|
@ -339,9 +339,12 @@ def process_image_changes(namespace, repository, image_id):
|
||||||
|
|
||||||
image_diffs_path = store.image_file_diffs_path(namespace, repository,
|
image_diffs_path = store.image_file_diffs_path(namespace, repository,
|
||||||
image_id)
|
image_id)
|
||||||
|
image_trie_path = store.image_file_trie_path(namespace, repository,
|
||||||
|
image_id)
|
||||||
|
|
||||||
if store.exists(image_diffs_path):
|
if store.exists(image_diffs_path):
|
||||||
logger.debug('Diffs already exist for image: %s' % image_id)
|
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)
|
image = model.get_image_by_id(namespace, repository, image_id)
|
||||||
parents = model.get_parent_images(image)
|
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
|
(new_trie, added, changed, removed) = new_metadata
|
||||||
|
|
||||||
# Write out the new trie
|
# Write out the new trie
|
||||||
new_trie_path = store.image_file_trie_path(namespace, repository, image_id)
|
store.put_content(image_trie_path, new_trie.tobytes())
|
||||||
store.put_content(new_trie_path, new_trie.tobytes())
|
|
||||||
|
|
||||||
# Write out the diffs
|
# Write out the diffs
|
||||||
diffs = {}
|
diffs = {}
|
||||||
|
@ -381,4 +383,4 @@ def process_image_changes(namespace, repository, image_id):
|
||||||
diffs[section].sort()
|
diffs[section].sort()
|
||||||
store.put_content(image_diffs_path, json.dumps(diffs, indent=2))
|
store.put_content(image_diffs_path, json.dumps(diffs, indent=2))
|
||||||
|
|
||||||
return new_trie_path
|
return image_trie_path
|
||||||
|
|
|
@ -8,26 +8,31 @@ AUFS_METADATA = u'.wh..wh.'
|
||||||
AUFS_WHITEOUT = u'.wh.'
|
AUFS_WHITEOUT = u'.wh.'
|
||||||
AUFS_WHITEOUT_PREFIX_LENGTH = len(AUFS_WHITEOUT)
|
AUFS_WHITEOUT_PREFIX_LENGTH = len(AUFS_WHITEOUT)
|
||||||
|
|
||||||
|
ALLOWED_TYPES = {tarfile.REGTYPE, tarfile.AREGTYPE}
|
||||||
|
|
||||||
|
|
||||||
def files_and_dirs_from_tar(source_stream, removed_prefix_collector):
|
def files_and_dirs_from_tar(source_stream, removed_prefix_collector):
|
||||||
tar_stream = tarfile.open(mode='r|*', fileobj=source_stream)
|
tar_stream = tarfile.open(mode='r|*', fileobj=source_stream)
|
||||||
|
|
||||||
for tar_info in tar_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)
|
filename = os.path.basename(absolute)
|
||||||
|
|
||||||
|
# Skip directories and metadata
|
||||||
if (filename.startswith(AUFS_METADATA) or
|
if (filename.startswith(AUFS_METADATA) or
|
||||||
absolute.startswith(AUFS_METADATA)):
|
absolute.startswith(AUFS_METADATA)):
|
||||||
# Skip
|
# Skip
|
||||||
continue
|
continue
|
||||||
|
|
||||||
elif filename.startswith(AUFS_WHITEOUT):
|
elif filename.startswith(AUFS_WHITEOUT):
|
||||||
filename = filename[AUFS_WHITEOUT_PREFIX_LENGTH:]
|
removed_filename = filename[AUFS_WHITEOUT_PREFIX_LENGTH:]
|
||||||
removed_prefix_collector.add(absolute)
|
removed_prefix = os.path.join('/', dirname, removed_filename)
|
||||||
|
removed_prefix_collector.add(removed_prefix)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
else:
|
elif tar_info.type in ALLOWED_TYPES:
|
||||||
yield "/" + absolute
|
yield '/' + absolute
|
||||||
|
|
||||||
|
|
||||||
def __compute_removed(base_trie, removed_prefixes):
|
def __compute_removed(base_trie, removed_prefixes):
|
||||||
|
|
Reference in a new issue