From 37cc186c0b4daf1a5ce3f761ad7afa93fabf9d49 Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Wed, 27 Oct 2021 10:58:10 +0200 Subject: [PATCH] delta: trim path when computing src files set The path contains an ending "/" which wouldn't match when we walk dst as it's not there. That had the unpleasant effect of creating empty folders in the destinations --- pkg/api/core/image/delta_test.go | 2 +- pkg/api/core/image/extract.go | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/api/core/image/delta_test.go b/pkg/api/core/image/delta_test.go index 2dba3c86..e5127df9 100644 --- a/pkg/api/core/image/delta_test.go +++ b/pkg/api/core/image/delta_test.go @@ -79,7 +79,7 @@ var _ = Describe("Delta", func() { ) Expect(err).ToNot(HaveOccurred()) defer os.RemoveAll(tmpdir) // clean up - + Expect(file.Exists(filepath.Join(tmpdir, "home"))).To(BeFalse()) Expect(file.Exists(filepath.Join(tmpdir, "root", ".cache"))).To(BeTrue()) Expect(file.Exists(filepath.Join(tmpdir, "bin", "sh"))).To(BeFalse()) Expect(file.Exists(filepath.Join(tmpdir, "usr", "local", "go"))).To(BeTrue()) diff --git a/pkg/api/core/image/extract.go b/pkg/api/core/image/extract.go index c5db6df0..09647322 100644 --- a/pkg/api/core/image/extract.go +++ b/pkg/api/core/image/extract.go @@ -67,10 +67,17 @@ func ExtractDeltaAdditionsFiles( if err != nil { return nil, err } - filesSrc.Set(hdr.Name, "") + + switch hdr.Typeflag { + case tar.TypeDir: + filesSrc.Set(filepath.Dir(hdr.Name), "") + default: + filesSrc.Set(hdr.Name, "") + } } return func(h *tar.Header) (bool, error) { + fileName := filepath.Join(string(os.PathSeparator), h.Name) _, exists := filesSrc.Get(h.Name) if exists {