feat: If the required chart is already cached, there is no need to download it again

Signed-off-by: ithrael <wh01096045@gmail.com>
pull/12628/head
ithrael 2 years ago
parent e6edb15067
commit 7986f60ddf

@ -97,11 +97,6 @@ func (c *ChartDownloader) DownloadTo(ref, version, dest string) (string, *proven
return "", nil, err
}
data, err := g.Get(u.String(), c.Options...)
if err != nil {
return "", nil, err
}
name := filepath.Base(u.Path)
if u.Scheme == registry.OCIScheme {
idx := strings.LastIndexByte(name, ':')
@ -109,9 +104,23 @@ func (c *ChartDownloader) DownloadTo(ref, version, dest string) (string, *proven
}
destfile := filepath.Join(dest, name)
_, err = os.Stat(destfile)
// If the required chart is already cached, there is no need to download it again
if err != nil {
if os.IsNotExist(err) {
data, err := g.Get(u.String(), c.Options...)
if err != nil {
return "", nil, err
}
if err := fileutil.AtomicWriteFile(destfile, data, 0644); err != nil {
return destfile, nil, err
}
} else {
return destfile, nil, err
}
}
// If provenance is requested, verify it.
ver := &provenance.Verification{}

@ -197,7 +197,9 @@ func TestDownloadTo(t *testing.T) {
},
}
cname := "/signtest-0.1.0.tgz"
dest := srv.Root()
dest := srv.Root() + "/dest"
os.Mkdir(dest, 0755)
where, v, err := c.DownloadTo(srv.URL()+cname, "", dest)
if err != nil {
t.Fatal(err)
@ -248,7 +250,8 @@ func TestDownloadTo_TLS(t *testing.T) {
Options: []getter.Option{},
}
cname := "test/signtest"
dest := srv.Root()
dest := srv.Root() + "/dest"
os.Mkdir(dest, 0755)
where, v, err := c.DownloadTo(cname, "", dest)
if err != nil {
t.Fatal(err)

Loading…
Cancel
Save