From b8d2b1b49e01b97927feeed44279df8b331af9c3 Mon Sep 17 00:00:00 2001 From: jockeych Date: Thu, 2 Apr 2020 12:32:39 -0700 Subject: [PATCH] fix the bug of deleting file from disk (#313) * fix the bug of deleting file from disk * resolve comments * add integration test --- lib/snapshot/mem_fs.go | 4 ++-- test/python/test_build.py | 11 ++++++++++- testdata/build-context/remove/Dockerfile | 3 +++ 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 testdata/build-context/remove/Dockerfile diff --git a/lib/snapshot/mem_fs.go b/lib/snapshot/mem_fs.go index 2b595b3c..6417f720 100644 --- a/lib/snapshot/mem_fs.go +++ b/lib/snapshot/mem_fs.go @@ -215,7 +215,7 @@ func (fs *MemFS) UpdateFromTarReader(r *tar.Reader, untar bool) error { return fmt.Errorf("untar one item %s: %s", path, err) } } - if err := fs.maybeAddToLayer(l, "", pathutils.AbsPath(hdr.Name), hdr, false); err != nil { + if err := fs.maybeAddToLayer(l, pathutils.AbsPath(hdr.Name), pathutils.AbsPath(hdr.Name), hdr, false); err != nil { return fmt.Errorf("add hdr from tar to layer: %s", err) } } @@ -229,7 +229,7 @@ func (fs *MemFS) UpdateFromTarReader(r *tar.Reader, untar bool) error { return fmt.Errorf("untar one item %s: %s", path, err) } } - if err := fs.maybeAddToLayer(l, "", pathutils.AbsPath(hdr.Name), hdr, false); err != nil { + if err := fs.maybeAddToLayer(l, pathutils.AbsPath(hdr.Name), pathutils.AbsPath(hdr.Name), hdr, false); err != nil { return fmt.Errorf("add hdr from tar to layer: %s", err) } } diff --git a/test/python/test_build.py b/test/python/test_build.py index 39adeb72..014e7dd8 100644 --- a/test/python/test_build.py +++ b/test/python/test_build.py @@ -5,7 +5,6 @@ import image - def test_build_simple(registry1, registry2, storage_dir): new_image = utils.new_image_name() replica_image = utils.new_image_name() @@ -22,6 +21,16 @@ def test_build_simple(registry1, registry2, storage_dir): assert code == 0, err +def test_build_remove(registry1, storage_dir): + new_image = utils.new_image_name() + context_dir = os.path.join( + os.getcwd(), 'testdata/build-context/remove') + utils.makisu_build_image( + new_image, context_dir, storage_dir, registry=registry1.addr) + code, err = utils.docker_run_image(registry1.addr, new_image) + assert code == 0, err + + def test_build_symlink(registry1, storage_dir): new_image = utils.new_image_name() context_dir = os.path.join( diff --git a/testdata/build-context/remove/Dockerfile b/testdata/build-context/remove/Dockerfile new file mode 100644 index 00000000..1a22665c --- /dev/null +++ b/testdata/build-context/remove/Dockerfile @@ -0,0 +1,3 @@ +FROM centos:7 +RUN rm -vf /etc/yum.repos.d/* +ENTRYPOINT ["/bin/bash", "-c", "echo $(ls -la /etc/yum.repos.d/)"]