Unverified Commit 8ca89cfb authored by Matthew Fisher's avatar Matthew Fisher Committed by GitHub

Merge pull request #3113 from joonix/issue-1639

Walk symbolic link directories
parents ab46779b 7cc61096
...@@ -243,7 +243,7 @@ func LoadDir(dir string) (*chart.Chart, error) { ...@@ -243,7 +243,7 @@ func LoadDir(dir string) (*chart.Chart, error) {
files := []*BufferedFile{} files := []*BufferedFile{}
topdir += string(filepath.Separator) topdir += string(filepath.Separator)
err = filepath.Walk(topdir, func(name string, fi os.FileInfo, err error) error { walk := func(name string, fi os.FileInfo, err error) error {
n := strings.TrimPrefix(name, topdir) n := strings.TrimPrefix(name, topdir)
if n == "" { if n == "" {
// No need to process top level. Avoid bug with helmignore .* matching // No need to process top level. Avoid bug with helmignore .* matching
...@@ -278,10 +278,45 @@ func LoadDir(dir string) (*chart.Chart, error) { ...@@ -278,10 +278,45 @@ func LoadDir(dir string) (*chart.Chart, error) {
files = append(files, &BufferedFile{Name: n, Data: data}) files = append(files, &BufferedFile{Name: n, Data: data})
return nil return nil
}) }
if err != nil { if err = filepath.Walk(topdir, symWalk(topdir, "", walk)); err != nil {
return c, err return c, err
} }
return LoadFiles(files) return LoadFiles(files)
} }
// symWalk walks topdir with optional symbolic link dir, symdir. The symdir will
// be used as the path name sent to walkFn.
func symWalk(topdir, symdir string, walkFn filepath.WalkFunc) filepath.WalkFunc {
return func(name string, fi os.FileInfo, err error) error {
// Recover the symbolic path instead of the real path.
if symdir != "" {
relative, err := filepath.Rel(topdir, name)
if err != nil {
return err
}
name = filepath.Join(symdir, relative)
}
// Recursively walk symlinked directories.
if isSymlink(fi) {
resolved, err := filepath.EvalSymlinks(name)
if err != nil {
return fmt.Errorf("error evaluating symlink %s: %s", name, err)
}
if fi, err = os.Lstat(resolved); err != nil {
return err
}
if fi.IsDir() {
return filepath.Walk(resolved, symWalk(resolved, name, walkFn))
}
}
return walkFn(name, fi, err)
}
}
func isSymlink(fi os.FileInfo) bool {
return fi.Mode()&os.ModeSymlink != 0
}
...@@ -425,6 +425,19 @@ func TestDependentChartWithSubChartsHelmignore(t *testing.T) { ...@@ -425,6 +425,19 @@ func TestDependentChartWithSubChartsHelmignore(t *testing.T) {
} }
} }
func TestDependentChartsWithSubChartsSymlink(t *testing.T) {
c, err := Load("testdata/joonix")
if err != nil {
t.Fatalf("Failed to load testdata: %s", err)
}
if c.Metadata.Name != "joonix" {
t.Fatalf("Unexpected chart name: %s", c.Metadata.Name)
}
if n := len(c.Dependencies); n != 1 {
t.Fatalf("Expected 1 dependency for this chart, but got %d", n)
}
}
func TestDependentChartsWithSubchartsAllSpecifiedInRequirements(t *testing.T) { func TestDependentChartsWithSubchartsAllSpecifiedInRequirements(t *testing.T) {
c, err := Load("testdata/dependent-chart-with-all-in-requirements-yaml") c, err := Load("testdata/dependent-chart-with-all-in-requirements-yaml")
if err != nil { if err != nil {
......
apiVersion: v1
description: A Helm chart for Kubernetes
name: joonix
version: 1.2.3
../../frobnitz
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment