Add CopyChart()

Signed-off-by: Reinaldo de Souza Jr <github@rei.nal.do>
pull/8831/head
Reinaldo de Souza Jr 5 years ago
parent f6d7363654
commit bd59588aaf

@ -98,20 +98,25 @@ func (c *ChartDownloader) DownloadTo(ref, version, dest string) (string, *proven
}
// Copy the chart from cache to dest path, using the standard name (not the cache key)
u, _, _ := c.resolveChartVersion(ref, version)
destPath := filepath.Join(dest, path.Base(u.String()))
if err := fileutil.AtomicCopyFile(chartPath, destPath, 0644); err != nil {
return destPath, ver, err
dstPath, err := CopyChart(chartPath, dest)
return dstPath, ver, err
}
// CopyChart copies a chart to a destination path. If provenance file is available, it will also be copied to the same parent dir.
func CopyChart(srcPath, dstDir string) (string, error) {
dstPath := filepath.Join(dstDir, path.Base(srcPath))
if err := fileutil.AtomicCopyFile(srcPath, dstPath, 0644); err != nil {
return dstPath, err
}
// Even though provenance is already verified on c.Fetch(), we still need to copy the file
// This is the expected behavior on `helm pull` for example, and it is used on tests.
chartProvenancePath := chartPath + provenanceFileExtension
chartProvenancePath := srcPath + provenanceFileExtension
if _, err := os.Stat(chartProvenancePath); !os.IsNotExist(err) {
return destPath, ver, fileutil.AtomicCopyFile(chartProvenancePath, destPath+provenanceFileExtension, 0644)
return dstPath, fileutil.AtomicCopyFile(chartProvenancePath, dstPath+provenanceFileExtension, 0644)
}
return destPath, ver, nil
return dstPath, nil
}
// Returns the URL for the provenance file of a chart

@ -33,7 +33,6 @@ import (
"github.com/pkg/errors"
"sigs.k8s.io/yaml"
"helm.sh/helm/v3/internal/fileutil"
"helm.sh/helm/v3/internal/resolver"
"helm.sh/helm/v3/internal/third_party/dep/fs"
"helm.sh/helm/v3/internal/urlutil"
@ -362,18 +361,8 @@ func (m *Manager) downloadAll(deps []*chart.Dependency) error {
// Copying files over
for _, downloadedChart := range downloadedCharts {
dst := filepath.Join(destPath, filepath.Base(downloadedChart))
if err := fileutil.AtomicCopyFile(downloadedChart, dst, 0644); err != nil {
return err
}
// TODO: confirm if there's any reason to include provenance files in charts/ for an unpacked chart.
chartProvenancePath := downloadedChart + provenanceFileExtension
if _, err := os.Stat(chartProvenancePath); os.IsNotExist(err) {
continue
}
if err := fileutil.AtomicCopyFile(chartProvenancePath, dst+provenanceFileExtension, 0644); err != nil {
if _, err := CopyChart(downloadedChart, destPath); err != nil {
return err
}
}

Loading…
Cancel
Save