Correctly handle dependency copy

Dependencies were not being copied correctly when `--untar` was set
because when the archive is uncompressed it creates a directory
structure which was skipped by the copy code. This updates it so it
correctly handles the directories (when the untar option is set).

Additionally I found an issue when testing which prevented the archive
from being expanded because the directory was being removed before it
could be processed. This has been fixed by changing the `os.RemoveAll`
to `os.Remove` in the untar handling code. The tmp directory `tmpPath`
is already marked for deletion when it's created

Signed-off-by: Andrea Tartaglia <me@andreatartaglia.com>
pull/30616/head
Andrea Tartaglia 2 months ago
parent 4380d19ad3
commit 5d7a418a8a
No known key found for this signature in database

@ -353,7 +353,7 @@ func (m *Manager) downloadAll(deps []*chart.Dependency) error {
getter.WithTagName(version))
}
_, v, err := dl.DownloadTo(churl, version, tmpPath)
d, v, err := dl.DownloadTo(churl, version, tmpPath)
if err != nil {
saveErrors = append(saveErrors, fmt.Errorf("could not download %s: %w", churl, err))
break
@ -368,16 +368,11 @@ func (m *Manager) downloadAll(deps []*chart.Dependency) error {
}
if m.Untar {
tmpDest, err := os.MkdirTemp("", "helm-dependency-")
if err != nil {
saveErrors = append(saveErrors, fmt.Errorf("failed to create temp dir: %w", err))
break
}
if err := chartutil.ExpandFile(tmpDest, tmpPath); err != nil {
if err := chartutil.ExpandFile(tmpPath, d); err != nil {
saveErrors = append(saveErrors, fmt.Errorf("failed to expand chart %s: %w", tmpPath, err))
break
}
defer os.RemoveAll(tmpDest)
defer os.Remove(d)
}
churls[churl] = struct{}{}
@ -438,9 +433,36 @@ func (m *Manager) safeMoveDeps(deps []*chart.Dependency, source, dest string) er
}
for _, file := range sourceFiles {
if file.IsDir() {
if file.IsDir() && m.Untar {
dirName := file.Name()
sourcedir := filepath.Join(source, dirName)
destdir := filepath.Join(dest, dirName)
// Ensure destination directory exists
if err := os.MkdirAll(destdir, 0755); err != nil {
fmt.Fprintf(m.Out, "Could not create directory %s: %s (Skipping)\n", destdir, err)
continue
}
// Load the chart to verify it's valid
_, err := loader.Load(sourcedir)
if err != nil {
fmt.Fprintf(m.Out, "Could not verify %s for moving: %s (Skipping)\n", sourcedir, err)
continue
}
// Mark this chart as existing in source
existsInSourceDirectory[dirName] = true
// Copy directory contents to destination
if err := fs.CopyDir(sourcedir, destdir); err != nil {
fmt.Fprintf(m.Out, "Unable to copy %s to charts dir: %s (Skipping)\n", sourcedir, err)
continue
}
continue
}
filename := file.Name()
sourcefile := filepath.Join(source, filename)
destfile := filepath.Join(dest, filename)

Loading…
Cancel
Save