grafana/pkg/cmd/grafana-cli/services/io_util.go
Jo ca72cd570e
Remove ioutil.ReadDir from usage (#53550)
* add depguard rule for ioutil

* replace ioutil.ReadDir with os.ReadDir

* use legacy option in depguard supported in golangci-lint v1.40

* replace ioutil.ReadDir with os.ReadDir

* return error for file info
2022-08-11 07:21:12 -04:00

30 lines
697 B
Go

package services
import (
"io/fs"
"os"
)
type IoUtilImp struct {
}
func (i IoUtilImp) Stat(path string) (os.FileInfo, error) {
return os.Stat(path)
}
func (i IoUtilImp) RemoveAll(path string) error {
return os.RemoveAll(path)
}
func (i IoUtilImp) ReadDir(path string) ([]fs.DirEntry, error) {
return os.ReadDir(path)
}
func (i IoUtilImp) ReadFile(filename string) ([]byte, error) {
// We can ignore the gosec G304 warning on this one, since the variable part of the file path stems
// from command line flag "pluginsDir". If the user shouldn't be reading from this directory, they shouldn't have
// the permission in the file system.
// nolint:gosec
return os.ReadFile(filename)
}