refactor(repo): Use byte buffer to build index file (#32579)

The string returned by the string builder was cast to a byte slice
anyways. Remove this indirection. Also, write directly to the buffer
instead of using fmt.Fprintln(...).

Signed-off-by: Tom Wieczorek <twieczorek@mirantis.com>
pull/32596/head
Tom Wieczorek 1 week ago committed by GitHub
parent 28e64bd2dd
commit 37752b70b2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -104,14 +104,15 @@ func (r *ChartRepository) DownloadIndexFile() (string, error) {
} }
// Create the chart list file in the cache directory // Create the chart list file in the cache directory
var charts strings.Builder var charts bytes.Buffer
for name := range indexFile.Entries { for name := range indexFile.Entries {
fmt.Fprintln(&charts, name) charts.WriteString(name)
charts.WriteByte('\n') // Terminate each entry with a newline
} }
chartsFile := filepath.Join(r.CachePath, helmpath.CacheChartsFile(r.Config.Name)) chartsFile := filepath.Join(r.CachePath, helmpath.CacheChartsFile(r.Config.Name))
os.MkdirAll(filepath.Dir(chartsFile), 0o755) os.MkdirAll(filepath.Dir(chartsFile), 0o755)
fileutil.AtomicWriteFile(chartsFile, bytes.NewReader([]byte(charts.String())), 0o644) fileutil.AtomicWriteFile(chartsFile, &charts, 0o644)
// Create the index file in the cache directory // Create the index file in the cache directory
fname := filepath.Join(r.CachePath, helmpath.CacheIndexFile(r.Config.Name)) fname := filepath.Join(r.CachePath, helmpath.CacheIndexFile(r.Config.Name))

Loading…
Cancel
Save