diff --git a/pkg/action/pull.go b/pkg/action/pull.go index be71d0ed0..2cd6aa646 100644 --- a/pkg/action/pull.go +++ b/pkg/action/pull.go @@ -152,23 +152,6 @@ func (p *Pull) Run(chartRef string) (string, error) { if !filepath.IsAbs(ud) { ud = filepath.Join(p.DestDir, ud) } - // Let udCheck to check conflict file/dir without replacing ud when untarDir is the current directory(.). - udCheck := ud - if udCheck == "." { - _, udCheck = filepath.Split(chartRef) - } else { - _, chartName := filepath.Split(chartRef) - udCheck = filepath.Join(udCheck, chartName) - } - - if _, err := os.Stat(udCheck); err != nil { - if err := os.MkdirAll(udCheck, 0755); err != nil { - return out.String(), fmt.Errorf("failed to untar (mkdir): %w", err) - } - } else { - return out.String(), fmt.Errorf("failed to untar: a file or directory with the name %s already exists", udCheck) - } - return out.String(), chartutil.ExpandFile(ud, saved) } return out.String(), nil diff --git a/pkg/chart/v2/util/expand.go b/pkg/chart/v2/util/expand.go index 9d08571ed..b78482693 100644 --- a/pkg/chart/v2/util/expand.go +++ b/pkg/chart/v2/util/expand.go @@ -61,6 +61,15 @@ func Expand(dir string, r io.Reader) error { return err } + // Check if chartdir conflict with an already existing directory + if _, err := os.Stat(chartdir); err != nil { + if err := os.MkdirAll(chartdir, 0755); err != nil { + return fmt.Errorf("failed to untar (mkdir): %w", err) + } + } else { + return fmt.Errorf("failed to untar: a file or directory with the name %s already exists", chartdir) + } + // Copy all files verbatim. We don't parse these files because parsing can remove // comments. for _, file := range files {