Fix bug in dockerloadformat and make sure we handle exceptions properly in the verb call

This commit is contained in:
Joseph Schorr 2014-10-08 13:43:12 -04:00
parent c34a8b6727
commit d16fdde528
4 changed files with 35 additions and 7 deletions

View file

@ -26,7 +26,6 @@ def build_docker_load_stream(namespace, repository, tag, synthetic_image_id,
def _import_format_generator(namespace, repository, tag, synthetic_image_id,
layer_json, get_image_iterator, get_layer_iterator):
# Docker import V1 Format (.tar):
# repositories - JSON file containing a repo -> tag -> image map
# {image ID folder}:
@ -69,7 +68,7 @@ def _import_format_generator(namespace, repository, tag, synthetic_image_id,
yielded_size += len(entry)
# If the yielded size is more than the estimated size (which is unlikely but possible), then
# raise an exception since the tar header will be wrong.
# raise an exception since the tar header will be wrong.
if yielded_size > estimated_file_size:
raise FileEstimationException()
@ -114,6 +113,7 @@ def _tar_file_padding(length):
if length % 512 != 0:
return '\0' * (512 - (length % 512))
return ''
def _tar_file_header(name, file_size):
info = tarfile.TarInfo(name=name)

View file

@ -12,6 +12,11 @@ class QueueFile(object):
self._buffer = ''
self._total_size = 0
self._name = name
self.raised_exception = False
self._exception_handlers = []
def add_exception_handler(self, handler):
self._exception_handlers.append(handler)
def read(self, size=8192):
if self._closed or self._done:
@ -25,7 +30,11 @@ class QueueFile(object):
if isinstance(result, Exception):
self._closed = True
raise result
self.raised_exception = True
for handler in self._exception_handlers:
handler(result)
return
self._buffer += result
self._total_size += len(result)