Skip to content

Commit

Permalink
params: avoid deprecated ioutil.ReadDir
Browse files Browse the repository at this point in the history
ioutil.ReadDir was deprecated in Go 1.16, and the lint workflow has
started to flag it.  The suggested replacement is os.ReadDir, which
returns a list of fs.DirEntry.  For this spot, the downstream code
expects a list of fs.FileInfo, so add the wrapper suggested in the Go
docs.
  • Loading branch information
kyleam committed Aug 21, 2024
1 parent 7d5e572 commit 68fc321
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions cmd/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ package cmd

import (
"fmt"
"io/ioutil"
"io/fs"
"os"
"path/filepath"
"runtime"
"sort"
Expand Down Expand Up @@ -221,13 +222,30 @@ func sortParams(params []string) []string {
return sorted
}

func readDir(dirname string) ([]fs.FileInfo, error) {
entries, err := os.ReadDir(dirname)
if err != nil {
return nil, err
}
infos := make([]fs.FileInfo, 0, len(entries))
for _, entry := range entries {
info, err := entry.Info()
if err != nil {
return infos, err
}
infos = append(infos, info)
}

return infos, nil
}

func params(cmd *cobra.Command, args []string) {
if debug {
viper.Debug()
}
var modelDirs []string
if dir != "" {
fi, err := ioutil.ReadDir(dir)
fi, err := readDir(dir)
if err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit 68fc321

Please sign in to comment.