From 0fc00545c33f67d3cc678b3b5da32e03666aa358 Mon Sep 17 00:00:00 2001 From: Shane Canon Date: Tue, 19 Feb 2019 10:41:05 -0800 Subject: [PATCH 1/2] Fix for Issue 244 Imported images have an extra './' in the tar file paths. If a later layer that builds on that import changes a directory to a file or link, the paths will be different. So this normalizes the paths across all the layers by stripping off any './' prefix. It adds a test too. --- imagegw/shifter_imagegw/dockerv2.py | 4 ++++ imagegw/test/dockerv2_test.py | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/imagegw/shifter_imagegw/dockerv2.py b/imagegw/shifter_imagegw/dockerv2.py index f3678a4b..10b8370b 100755 --- a/imagegw/shifter_imagegw/dockerv2.py +++ b/imagegw/shifter_imagegw/dockerv2.py @@ -626,6 +626,10 @@ def filter_layer(layer_members, to_remove): members = filter_layer(members, 'dev/') members = filter_layer(members, '/') members = [x for x in members if not x.name.find('..') >= 0] + for x in members: + if x.name[0:2] == './': + x.name=x.name[2:] + # find all whiteouts whiteouts = [x for x in members diff --git a/imagegw/test/dockerv2_test.py b/imagegw/test/dockerv2_test.py index 0c6c7ca5..19ada049 100644 --- a/imagegw/test/dockerv2_test.py +++ b/imagegw/test/dockerv2_test.py @@ -105,6 +105,18 @@ def test_chgtype(self): bfile = os.path.join(resp['expandedpath'], 'build/test2') assert os.path.exists(bfile) + def test_import(self): + cache = tempfile.mkdtemp() + expand = tempfile.mkdtemp() + self.cleanpaths.append(cache) + self.cleanpaths.append(expand) + + resp = dockerv2.pull_image(self.options, 'scanon/importtest', 'latest', + cachedir=cache, expanddir=expand) + assert os.path.exists(resp['expandedpath']) + bfile = os.path.join(resp['expandedpath'], 'home') + self.assertTrue(os.path.islink(bfile)) + def test_need_proxy(self): """ Test if proxy is needed From 8aac2c9437320a2eb3b85da6a139828d35378f83 Mon Sep 17 00:00:00 2001 From: Shane Canon Date: Tue, 19 Feb 2019 13:33:43 -0800 Subject: [PATCH 2/2] Move the normalization before the filters. --- imagegw/shifter_imagegw/dockerv2.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/imagegw/shifter_imagegw/dockerv2.py b/imagegw/shifter_imagegw/dockerv2.py index 10b8370b..87ef3b98 100755 --- a/imagegw/shifter_imagegw/dockerv2.py +++ b/imagegw/shifter_imagegw/dockerv2.py @@ -622,14 +622,14 @@ def filter_layer(layer_members, to_remove): # get directory of tar contents members = tfp.getmembers() + # Normalize paths + for x in members: + if x.name[0:2] == './': + x.name = x.name[2:] # remove all illegal files members = filter_layer(members, 'dev/') members = filter_layer(members, '/') members = [x for x in members if not x.name.find('..') >= 0] - for x in members: - if x.name[0:2] == './': - x.name=x.name[2:] - # find all whiteouts whiteouts = [x for x in members