Fix for mapping translations for existing images.

This commit is contained in:
jakedt 2014-02-21 08:00:47 -05:00
parent f8eb0c983f
commit f339160ab9
2 changed files with 18 additions and 5 deletions

View file

@ -884,16 +884,26 @@ def create_repository(namespace, name, creating_user, visibility='private'):
return repo
def __translate_ancestry(old_ancestry, translations):
def __translate_ancestry(old_ancestry, translations, existing_images):
if old_ancestry == '/':
return '/'
def translate_id(old_id):
if old_id not in translations:
# Figure out which docker_image_id the old id refers to, then find a
# a local one
old = Image.select(Image.docker_image_id).where(Image.id == old_id).get()
translations[old_id] = existing_images[old.docker_image_id]
return translations[old_id]
old_ids = [int(id_str) for id_str in old_ancestry.split('/')[1:-1]]
new_ids = [str(translations[old_id]) for old_id in old_ids]
new_ids = [str(translate_id(old_id)) for old_id in old_ids]
return '/%s/' % '/'.join(new_ids)
def create_or_link_image(docker_image_id, repository, username, translations):
def create_or_link_image(docker_image_id, repository, username, translations,
existing_images):
with transaction_factory(db):
query = (Image
.select(Image, ImageStorage)
@ -916,7 +926,7 @@ def create_or_link_image(docker_image_id, repository, username, translations):
logger.debug(msg, docker_image_id, to_copy.storage.uuid)
new_image_ancestry = __translate_ancestry(to_copy.ancestors,
translations)
translations, existing_images)
storage = to_copy.storage
origin_image_id = to_copy.id

View file

@ -187,15 +187,18 @@ def create_repository(namespace, repository):
added_images = OrderedDict([(desc['id'], desc)
for desc in image_descriptions])
new_repo_images = dict(added_images)
existing_image_translations = {}
for existing in model.get_repository_images(namespace, repository):
if existing.docker_image_id in new_repo_images:
existing_image_translations[existing.docker_image_id] = existing.id
added_images.pop(existing.docker_image_id)
username = get_authenticated_user() and get_authenticated_user().username
translations = {}
for image_description in added_images.values():
model.create_or_link_image(image_description['id'], repo, username,
translations)
translations, existing_image_translations)
response = make_response('Created', 201)