Skip to content

Commit

Permalink
refactor: use os.ReadDir for lightweight directory reading
Browse files Browse the repository at this point in the history
`os.ReadDir` was added in Go 1.16 as part of the deprecation of `ioutil`
package. It is a more efficient implementation than `ioutil.ReadDir` as
stated here https://pkg.go.dev/io/ioutil#ReadDir.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
(cherry picked from commit e12f357)
  • Loading branch information
Juneezee authored and hickeyma committed Feb 23, 2022
1 parent dbd30ca commit 6966dc4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/downloader/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,12 +400,12 @@ func parseOCIRef(chartRef string) (string, string, error) {
func (m *Manager) safeMoveDeps(deps []*chart.Dependency, source, dest string) error {
existsInSourceDirectory := map[string]bool{}
isLocalDependency := map[string]bool{}
sourceFiles, err := ioutil.ReadDir(source)
sourceFiles, err := os.ReadDir(source)
if err != nil {
return err
}
// attempt to read destFiles; fail fast if we can't
destFiles, err := ioutil.ReadDir(dest)
destFiles, err := os.ReadDir(dest)
if err != nil {
return err
}
Expand Down Expand Up @@ -436,7 +436,7 @@ func (m *Manager) safeMoveDeps(deps []*chart.Dependency, source, dest string) er
}

fmt.Fprintln(m.Out, "Deleting outdated charts")
// find all files that exist in dest that do not exist in source; delete them (outdated dependendencies)
// find all files that exist in dest that do not exist in source; delete them (outdated dependencies)
for _, file := range destFiles {
if !file.IsDir() && !existsInSourceDirectory[file.Name()] {
fname := filepath.Join(dest, file.Name())
Expand Down

0 comments on commit 6966dc4

Please sign in to comment.