Fix chart directory relative path bug

pull/522/head
jackgr 9 years ago
parent 7d6b82544b
commit a3cd0ec257

@ -220,20 +220,25 @@ func fname(name string) string {
// If you are just reading the Chart.yaml file, it is substantially more // If you are just reading the Chart.yaml file, it is substantially more
// performant to use LoadChartfile. // performant to use LoadChartfile.
func LoadDir(chart string) (*Chart, error) { func LoadDir(chart string) (*Chart, error) {
if fi, err := os.Stat(chart); err != nil { dir, err := filepath.Abs(chart)
if err != nil {
return nil, fmt.Errorf("%s is not a valid path", chart)
}
if fi, err := os.Stat(dir); err != nil {
return nil, err return nil, err
} else if !fi.IsDir() { } else if !fi.IsDir() {
return nil, fmt.Errorf("Chart %s is not a directory.", chart) return nil, fmt.Errorf("%s is not a directory", chart)
} }
cf, err := LoadChartfile(filepath.Join(chart, "Chart.yaml")) cf, err := LoadChartfile(filepath.Join(dir, "Chart.yaml"))
if err != nil { if err != nil {
return nil, err return nil, err
} }
cl := &dirChart{ cl := &dirChart{
chartyaml: cf, chartyaml: cf,
chartdir: chart, chartdir: dir,
} }
return &Chart{ return &Chart{
@ -293,9 +298,16 @@ func loadTar(r *tar.Reader) (*tarChart, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
// ioutil.TempDir uses Getenv("TMPDIR"), so there are no guarantees
dir, err := filepath.Abs(td)
if err != nil {
return nil, fmt.Errorf("%s is not a valid path", td)
}
c := &tarChart{ c := &tarChart{
chartyaml: &Chartfile{}, chartyaml: &Chartfile{},
tmpDir: td, tmpDir: dir,
} }
firstDir := "" firstDir := ""

@ -141,18 +141,19 @@ func TestChart(t *testing.T) {
t.Errorf("Unexpected chart file name: %s", c.Chartfile().Name) t.Errorf("Unexpected chart file name: %s", c.Chartfile().Name)
} }
dir := c.Dir()
d := c.DocsDir() d := c.DocsDir()
if d != filepath.Join(testdir, preDocs) { if d != filepath.Join(dir, preDocs) {
t.Errorf("Unexpectedly, docs are in %s", d) t.Errorf("Unexpectedly, docs are in %s", d)
} }
d = c.TemplatesDir() d = c.TemplatesDir()
if d != filepath.Join(testdir, preTemplates) { if d != filepath.Join(dir, preTemplates) {
t.Errorf("Unexpectedly, templates are in %s", d) t.Errorf("Unexpectedly, templates are in %s", d)
} }
d = c.HooksDir() d = c.HooksDir()
if d != filepath.Join(testdir, preHooks) { if d != filepath.Join(dir, preHooks) {
t.Errorf("Unexpectedly, hooks are in %s", d) t.Errorf("Unexpectedly, hooks are in %s", d)
} }
@ -160,7 +161,7 @@ func TestChart(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("No icon found in test chart: %s", err) t.Errorf("No icon found in test chart: %s", err)
} }
if i != filepath.Join(testdir, preIcon) { if i != filepath.Join(dir, preIcon) {
t.Errorf("Unexpectedly, icon is in %s", i) t.Errorf("Unexpectedly, icon is in %s", i)
} }
} }

Loading…
Cancel
Save