summaryrefslogtreecommitdiffstats
path: root/src/virtBootstrap/sources
diff options
context:
space:
mode:
authorRadostin Stoyanov <rstoyanov1@gmail.com>2017-08-26 21:41:55 +0100
committerRadostin Stoyanov <rstoyanov1@gmail.com>2017-08-28 15:58:39 +0100
commit376dd96934de59d72db5fde376533bcba2bdc670 (patch)
tree3a4d269119ef2efab4aa0edcad4f0aef8ae78204 /src/virtBootstrap/sources
parente9826e1a29dd045a1a6c680d0d709906da13488b (diff)
downloadvirt-bootstrap.git-376dd96934de59d72db5fde376533bcba2bdc670.tar.gz
virt-bootstrap.git-376dd96934de59d72db5fde376533bcba2bdc670.tar.xz
virt-bootstrap.git-376dd96934de59d72db5fde376533bcba2bdc670.zip
DockerSource: Split checksum and layers
The current implementation store in one list: - checksum - checksum type - file path - file size However, the information about checksum and checksum type is only used to verify the content of tarball before it is being extracted. Splitting these into separate lists would allow us to reuse the function untar_layers() with FileSource.
Diffstat (limited to 'src/virtBootstrap/sources')
-rw-r--r--src/virtBootstrap/sources/docker_source.py12
-rw-r--r--src/virtBootstrap/sources/file_source.py3
2 files changed, 12 insertions, 3 deletions
diff --git a/src/virtBootstrap/sources/docker_source.py b/src/virtBootstrap/sources/docker_source.py
index 54d8903..246356a 100644
--- a/src/virtBootstrap/sources/docker_source.py
+++ b/src/virtBootstrap/sources/docker_source.py
@@ -65,6 +65,7 @@ class DockerSource(object):
self.images_dir = utils.get_image_dir(self.no_cache)
self.manifest = None
self.layers = []
+ self.checksums = []
if self.username and not self.password:
self.password = getpass.getpass()
@@ -94,9 +95,13 @@ class DockerSource(object):
layer_digest = layer[digest_field]
layer_size = layer['size'] if 'size' in layer else None
+ # Store checksums of layers
sum_type, layer_sum = layer_digest.split(':')
+ self.checksums.append([sum_type, layer_sum])
+
+ # Store file path and size of each layer
file_path = os.path.join(self.images_dir, layer_sum + '.tar')
- self.layers.append([sum_type, layer_sum, file_path, layer_size])
+ self.layers.append([file_path, layer_size])
def gen_valid_uri(self, uri):
"""
@@ -230,7 +235,10 @@ class DockerSource(object):
and have valid hash sum.
"""
self.progress("Checking cached layers", value=0, logger=logger)
- for sum_type, sum_expected, path, _ignore in self.layers:
+ for index, checksum in enumerate(self.checksums):
+ path = self.layers[index][0]
+ sum_type, sum_expected = checksum
+
logger.debug("Checking layer: %s", path)
if not (os.path.exists(path)
and utils.checksum(path, sum_type, sum_expected)):
diff --git a/src/virtBootstrap/sources/file_source.py b/src/virtBootstrap/sources/file_source.py
index c02f735..412db8a 100644
--- a/src/virtBootstrap/sources/file_source.py
+++ b/src/virtBootstrap/sources/file_source.py
@@ -57,10 +57,11 @@ class FileSource(object):
if not os.path.isfile(self.path):
raise Exception('Invalid file source "%s"' % self.path)
+ layer = [[self.path, os.path.getsize(self.path)]]
if self.output_format == 'dir':
self.progress("Extracting files into destination directory",
value=0, logger=logger)
- utils.safe_untar(self.path, dest)
+ utils.untar_layers(layer, dest, self.progress)
elif self.output_format == 'qcow2':
# Remove the old path