MCPcopy
hub / github.com/helm/helm / Save

Function Save

pkg/chart/v2/util/save.go:108–155  ·  view source on GitHub ↗

Save creates an archived chart to the given directory. This takes an existing chart and a destination directory. If the directory is /foo, and the chart is named bar, with version 1.0.0, this will generate /foo/bar-1.0.0.tgz. This returns the absolute path to the chart archive file.

(c *chart.Chart, outDir string)

Source from the content-addressed store, hash-verified

106//
107// This returns the absolute path to the chart archive file.
108func Save(c *chart.Chart, outDir string) (string, error) {
109 if err := c.Validate(); err != nil {
110 return "", fmt.Errorf("chart validation: %w", err)
111 }
112
113 filename := fmt.Sprintf("%s-%s.tgz", c.Name(), c.Metadata.Version)
114 filename = filepath.Join(outDir, filename)
115 dir := filepath.Dir(filename)
116 if stat, err := os.Stat(dir); err != nil {
117 if errors.Is(err, fs.ErrNotExist) {
118 if err2 := os.MkdirAll(dir, 0755); err2 != nil {
119 return "", err2
120 }
121 } else {
122 return "", fmt.Errorf("stat %s: %w", dir, err)
123 }
124 } else if !stat.IsDir() {
125 return "", fmt.Errorf("is not a directory: %s", dir)
126 }
127
128 f, err := os.Create(filename)
129 if err != nil {
130 return "", err
131 }
132
133 // Wrap in gzip writer
134 zipper := gzip.NewWriter(f)
135 zipper.Extra = headerBytes
136 zipper.Comment = "Helm"
137
138 // Wrap in tar writer
139 twriter := tar.NewWriter(zipper)
140 rollback := false
141 defer func() {
142 twriter.Close()
143 zipper.Close()
144 f.Close()
145 if rollback {
146 os.Remove(filename)
147 }
148 }()
149
150 if err := writeTarContents(twriter, c, ""); err != nil {
151 rollback = true
152 return filename, err
153 }
154 return filename, nil
155}
156
157func writeTarContents(out *tar.Writer, c *chart.Chart, prefix string) error {
158 err := validateName(c.Name())

Callers 4

SaveDirFunction · 0.70
TestSaveFunction · 0.70
TestRepeatableSaveFunction · 0.70

Calls 8

IsMethod · 0.80
CloseMethod · 0.80
writeTarContentsFunction · 0.70
ValidateMethod · 0.65
NameMethod · 0.65
DirMethod · 0.65
CreateMethod · 0.65
RemoveMethod · 0.45

Tested by 3

TestSaveFunction · 0.56
TestRepeatableSaveFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…