From 5b77335415dc98c087a63bcd36c1d2db5ebf7dba Mon Sep 17 00:00:00 2001 From: Jean-Philippe Courson Date: Sat, 24 Feb 2018 17:12:37 +0000 Subject: [PATCH] Create missing directories when saving files in chartutil.SaveDir --- pkg/chartutil/save.go | 6 ++++++ pkg/chartutil/save_test.go | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/pkg/chartutil/save.go b/pkg/chartutil/save.go index b89917d96..bff32dde5 100644 --- a/pkg/chartutil/save.go +++ b/pkg/chartutil/save.go @@ -70,6 +70,12 @@ func SaveDir(c *chart.Chart, dest string) error { // Save files for _, f := range c.Files { n := filepath.Join(outdir, f.TypeUrl) + + d := filepath.Dir(n) + if err := os.MkdirAll(d, 0755); err != nil { + return err + } + if err := ioutil.WriteFile(n, f.Value, 0755); err != nil { return err } diff --git a/pkg/chartutil/save_test.go b/pkg/chartutil/save_test.go index 566999ff7..5e1564299 100644 --- a/pkg/chartutil/save_test.go +++ b/pkg/chartutil/save_test.go @@ -22,6 +22,7 @@ import ( "strings" "testing" + "github.com/golang/protobuf/ptypes/any" "k8s.io/helm/pkg/proto/hapi/chart" ) @@ -40,6 +41,9 @@ func TestSave(t *testing.T) { Values: &chart.Config{ Raw: "ship: Pequod", }, + Files: []*any.Any{ + {TypeUrl: "scheherazade/shahryar.txt", Value: []byte("1,001 Nights")}, + }, } where, err := Save(c, tmp) @@ -64,6 +68,9 @@ func TestSave(t *testing.T) { if c2.Values.Raw != c.Values.Raw { t.Fatal("Values data did not match") } + if len(c2.Files) != 1 || c2.Files[0].TypeUrl != "scheherazade/shahryar.txt" { + t.Fatal("Files data did not match") + } } func TestSaveDir(t *testing.T) { @@ -81,6 +88,9 @@ func TestSaveDir(t *testing.T) { Values: &chart.Config{ Raw: "ship: Pequod", }, + Files: []*any.Any{ + {TypeUrl: "scheherazade/shahryar.txt", Value: []byte("1,001 Nights")}, + }, } if err := SaveDir(c, tmp); err != nil { @@ -98,4 +108,7 @@ func TestSaveDir(t *testing.T) { if c2.Values.Raw != c.Values.Raw { t.Fatal("Values data did not match") } + if len(c2.Files) != 1 || c2.Files[0].TypeUrl != "scheherazade/shahryar.txt" { + t.Fatal("Files data did not match") + } }