Change back to using a docker load format
This commit is contained in:
parent
99d57752f5
commit
e273dca4b4
4 changed files with 160 additions and 31 deletions
|
@ -32,30 +32,30 @@ class StreamLayerMerger(object):
|
|||
chunk_size = 1024 * 1024 * 9
|
||||
|
||||
for tar_info in tar_file:
|
||||
result = self.process_tar_info(tar_info)
|
||||
if not result:
|
||||
if not self.check_tar_info(tar_info):
|
||||
continue
|
||||
|
||||
(tarinfo, filebuf) = result
|
||||
# Yield the tar header.
|
||||
yield tar_info.tobuf()
|
||||
|
||||
yield tarinfo.tobuf()
|
||||
# Try to extract any file contents for the tar. If found, we yield them as well.
|
||||
if tar_info.isreg():
|
||||
file_stream = tar_file.extractfile(tar_info)
|
||||
if file_stream is not None:
|
||||
length = 0
|
||||
while True:
|
||||
current_block = file_stream.read(chunk_size)
|
||||
if not len(current_block):
|
||||
break
|
||||
|
||||
if filebuf:
|
||||
length = 0
|
||||
file_stream = tar_file.extractfile(tarinfo)
|
||||
while True:
|
||||
current_block = file_stream.read(chunk_size)
|
||||
if not len(current_block):
|
||||
break
|
||||
yield current_block
|
||||
length += len(current_block)
|
||||
|
||||
yield current_block
|
||||
length += len(current_block)
|
||||
file_stream.close()
|
||||
|
||||
file_stream.close()
|
||||
|
||||
# Files must be padding to 512 byte multiples.
|
||||
if length % 512 != 0:
|
||||
yield '\0' * (512 - (length % 512))
|
||||
# Files must be padding to 512 byte multiples.
|
||||
if length % 512 != 0:
|
||||
yield '\0' * (512 - (length % 512))
|
||||
|
||||
# Close the layer stream now that we're done with it.
|
||||
tar_file.close()
|
||||
|
@ -68,24 +68,24 @@ class StreamLayerMerger(object):
|
|||
yield '\0' * 512
|
||||
|
||||
|
||||
def process_tar_info(self, tar_info):
|
||||
def check_tar_info(self, tar_info):
|
||||
absolute = os.path.relpath(tar_info.name.decode('utf-8'), './')
|
||||
|
||||
# Skip metadata.
|
||||
if is_aufs_metadata(absolute):
|
||||
return None
|
||||
return False
|
||||
|
||||
# Add any prefix of deleted paths to the prefix list.
|
||||
deleted_prefix = get_deleted_prefix(absolute)
|
||||
if deleted_prefix is not None:
|
||||
self.encountered.append(deleted_prefix)
|
||||
return None
|
||||
return False
|
||||
|
||||
# Check if this file has already been encountered somewhere. If so,
|
||||
# skip it.
|
||||
if unicode(absolute) in self.trie:
|
||||
return None
|
||||
return False
|
||||
|
||||
# Otherwise, add the path to the encountered list and return it.
|
||||
self.encountered.append(absolute)
|
||||
return (tar_info, tar_info.isfile() or tar_info.isdev())
|
||||
return True
|
||||
|
|
Reference in a new issue