Skip to content

Commit 4989088

Browse files
committed
replace deprecated io/ioutil
create separate function for retrieving file info from the path, export the func
1 parent 6e44d1e commit 4989088

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

go/buildutil/util.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"go/parser"
1212
"go/token"
1313
"io"
14-
"io/ioutil"
14+
"io/fs"
1515
"os"
1616
"path"
1717
"path/filepath"
@@ -180,7 +180,23 @@ func ReadDir(ctxt *build.Context, path string) ([]os.FileInfo, error) {
180180
if ctxt.ReadDir != nil {
181181
return ctxt.ReadDir(path)
182182
}
183-
return ioutil.ReadDir(path)
183+
return GetFileInfos(path)
184+
}
185+
186+
func GetFileInfos(path string) ([]os.FileInfo, error) {
187+
entries, err := os.ReadDir(path)
188+
if err != nil {
189+
return nil, err
190+
}
191+
infos := make([]fs.FileInfo, 0, len(entries))
192+
for _, entry := range entries {
193+
info, err := entry.Info()
194+
if err != nil {
195+
continue
196+
}
197+
infos = append(infos, info)
198+
}
199+
return infos, nil
184200
}
185201

186202
// SplitPathList behaves like filepath.SplitList,

0 commit comments

Comments
 (0)