From 5695ebc3d5bdfb5bd8f785ed7f5e71e0971f4ded Mon Sep 17 00:00:00 2001 From: peter-evans Date: Thu, 11 Oct 2018 09:28:55 +0900 Subject: [PATCH 1/4] Remove all at path to make way for new symlink --- pkg/util/fs_util.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/util/fs_util.go b/pkg/util/fs_util.go index 07e3fbc59..b43ee4df5 100644 --- a/pkg/util/fs_util.go +++ b/pkg/util/fs_util.go @@ -260,7 +260,7 @@ func extractFile(dest string, hdr *tar.Header, tr io.Reader) error { // Check if something already exists at path // If so, delete it if FilepathExists(path) { - if err := os.Remove(path); err != nil { + if err := os.RemoveAll(path); err != nil { return errors.Wrapf(err, "error removing %s to make way for new symlink", hdr.Name) } } From 796b2515a7819b908683a62b29e1586130ea575a Mon Sep 17 00:00:00 2001 From: peter-evans Date: Thu, 11 Oct 2018 11:18:26 +0900 Subject: [PATCH 2/4] Add test for symlink extraction to non-empty dir --- integration/dockerfiles/Dockerfile_test_extraction | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 integration/dockerfiles/Dockerfile_test_extraction diff --git a/integration/dockerfiles/Dockerfile_test_extraction b/integration/dockerfiles/Dockerfile_test_extraction new file mode 100644 index 000000000..8e64d8ade --- /dev/null +++ b/integration/dockerfiles/Dockerfile_test_extraction @@ -0,0 +1,2 @@ +# Tests extraction of a symlink to a path that is a non-empty directory +FROM registry.access.redhat.com/jboss-eap-7/eap71-openshift:1.3-10 From 38e8dc2cdd20c09c4f641f1fdd162e2f80854f03 Mon Sep 17 00:00:00 2001 From: peter-evans Date: Thu, 11 Oct 2018 15:33:25 +0900 Subject: [PATCH 3/4] Remove all at path to make way for new reg files and links --- pkg/util/fs_util.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/util/fs_util.go b/pkg/util/fs_util.go index b43ee4df5..3af1c5e85 100644 --- a/pkg/util/fs_util.go +++ b/pkg/util/fs_util.go @@ -193,7 +193,7 @@ func extractFile(dest string, hdr *tar.Header, tr io.Reader) error { // Check if something already exists at path (symlinks etc.) // If so, delete it if FilepathExists(path) { - if err := os.Remove(path); err != nil { + if err := os.RemoveAll(path); err != nil { return errors.Wrapf(err, "error removing %s to make way for new file.", path) } } @@ -242,7 +242,7 @@ func extractFile(dest string, hdr *tar.Header, tr io.Reader) error { // Check if something already exists at path // If so, delete it if FilepathExists(path) { - if err := os.Remove(path); err != nil { + if err := os.RemoveAll(path); err != nil { return errors.Wrapf(err, "error removing %s to make way for new link", hdr.Name) } } From d8beff6f28019345e979d6ec9fe192ca88441099 Mon Sep 17 00:00:00 2001 From: peter-evans Date: Sat, 13 Oct 2018 08:04:27 +0900 Subject: [PATCH 4/4] Update test for link and file extraction to non-empty dir --- integration/dockerfiles/Dockerfile_test_extraction | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/integration/dockerfiles/Dockerfile_test_extraction b/integration/dockerfiles/Dockerfile_test_extraction index 8e64d8ade..d2a3eaedd 100644 --- a/integration/dockerfiles/Dockerfile_test_extraction +++ b/integration/dockerfiles/Dockerfile_test_extraction @@ -1,2 +1,2 @@ -# Tests extraction of a symlink to a path that is a non-empty directory -FROM registry.access.redhat.com/jboss-eap-7/eap71-openshift:1.3-10 +# Tests extraction of symlink, hardlink and regular files to a path that is a non-empty directory +FROM gcr.io/kaniko-test/extraction-base-image:latest