From 8d34a6ebb190be51dd5601a76073397c58974070 Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Thu, 21 Oct 2021 21:29:24 +0200 Subject: [PATCH] Use the cache to store temporary download files --- pkg/installer/client/http.go | 8 ++++++++ pkg/installer/client/local.go | 8 ++++++++ pkg/installer/system_test.go | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/pkg/installer/client/http.go b/pkg/installer/client/http.go index adf926ed..9d134a3d 100644 --- a/pkg/installer/client/http.go +++ b/pkg/installer/client/http.go @@ -184,8 +184,16 @@ func (c *HttpClient) DownloadArtifact(a *artifact.PackageArtifact) (*artifact.Pa return nil, errors.Wrapf(err, "failed downloading %s", artifactName) } + defer os.RemoveAll(d) newart.Path = d c.Cache.Put(newart) + + fileName, err := c.Cache.Get(newart) + if err != nil { + return nil, errors.Wrapf(err, "failed getting file from cache %v", newart) + } + + newart.Path = fileName } return newart, nil diff --git a/pkg/installer/client/local.go b/pkg/installer/client/local.go index ffc4df2c..2f9e31fc 100644 --- a/pkg/installer/client/local.go +++ b/pkg/installer/client/local.go @@ -56,9 +56,17 @@ func (c *LocalClient) DownloadArtifact(a *artifact.PackageArtifact) (*artifact.P if err != nil { return nil, errors.Wrapf(err, "failed downloading %s", artifactName) } + defer os.RemoveAll(d) newart.Path = d c.Cache.Put(newart) + + fileName, err := c.Cache.Get(newart) + if err != nil { + return nil, errors.Wrapf(err, "failed getting file from cache %v", newart) + } + + newart.Path = fileName } return newart, nil diff --git a/pkg/installer/system_test.go b/pkg/installer/system_test.go index 72ed8526..cd7119f5 100644 --- a/pkg/installer/system_test.go +++ b/pkg/installer/system_test.go @@ -60,7 +60,7 @@ var _ = Describe("System", func() { r, p, err = s.ExistsPackageFile("f") Expect(r).To(BeTrue()) Expect(err).ToNot(HaveOccurred()) - Expect(p).To(Equal(b)) + Expect(p).To(Or(Equal(b), Equal(a))) // This fails r, p, err = s.ExistsPackageFile("barz") Expect(r).To(BeTrue()) Expect(err).ToNot(HaveOccurred())