From a04aae9d2154b9049548d9c4534ff8681600090c Mon Sep 17 00:00:00 2001 From: Cosmin Cojocar Date: Sun, 24 Feb 2019 19:50:29 +0100 Subject: [PATCH] Store only the packed charts in the charts folder when traversing the dependencies tree Signed-off-by: Cosmin Cojocar --- pkg/downloader/manager.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/pkg/downloader/manager.go b/pkg/downloader/manager.go index 6c4e3e4be..fb7827a87 100644 --- a/pkg/downloader/manager.go +++ b/pkg/downloader/manager.go @@ -57,6 +57,8 @@ type Manager struct { SkipUpdate bool // Recursive indicates that there is a recursive build Recursive bool + // recDestPath is the path where the packed charts are stored when the charts dependencies tree is traversed + recDestPath string // Getter collection for the operation Getters []getter.Provider } @@ -125,6 +127,13 @@ func (m *Manager) build() ([]*chartutil.Dependency, error) { // // If SkipUpdate is set, this will not update the repository. func (m *Manager) BuildRecursively() error { + // Prepare the folder where the chart archives will be stored recursively + recDestPath := filepath.Join(m.ChartPath, "reccharts") + if err := os.MkdirAll(recDestPath, 0755); err != nil { + return err + } + + m.recDestPath = recDestPath // Build the main chart dependencies, err := m.build() if err != nil { @@ -173,6 +182,17 @@ func (m *Manager) BuildRecursively() error { // Restore to the original value before running the recursive build m.SkipUpdate = prevSkipUpdate + // Remove the folder which contains the unpacked charts tree + err = os.RemoveAll(baseChartPath) + if err != nil { + return err + } + // Rename to "charts" the folder with all packed charts + err = os.Rename(recDestPath, baseChartPath) + if err != nil { + return err + } + return nil } @@ -306,6 +326,10 @@ func (m *Manager) downloadAll(deps []*chartutil.Dependency) error { if err != nil { return fmt.Errorf("could not unpack %s: %s", archiveFile, err) } + err = saveFile(m.recDestPath, archiveFile) + if err != nil { + return fmt.Errorf("could not save archive file %s: %s", archiveFile, err) + } } continue } @@ -342,6 +366,10 @@ func (m *Manager) downloadAll(deps []*chartutil.Dependency) error { if err != nil { return fmt.Errorf("could not unpack %s: %s", tarPath, err) } + err = saveFile(m.recDestPath, tarPath) + if err != nil { + return fmt.Errorf("could not save archive file %s: %s", tarPath, err) + } } } @@ -749,3 +777,13 @@ func move(tmpPath, destPath string) error { } return nil } + +func saveFile(destPath, filePath string) error { + file, err := ioutil.ReadFile(filePath) + if err != nil { + return err + } + filename := filepath.Base(filePath) + destfile := filepath.Join(destPath, filename) + return ioutil.WriteFile(destfile, file, 0644) +}