mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
package commandstest
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
type FakeIoUtil struct {
|
||||
FakeReadDir []os.FileInfo
|
||||
FakeReadDir []fs.DirEntry
|
||||
FakeIsDirectory bool
|
||||
}
|
||||
|
||||
@@ -18,7 +19,7 @@ func (util *FakeIoUtil) RemoveAll(path string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (util *FakeIoUtil) ReadDir(path string) ([]os.FileInfo, error) {
|
||||
func (util *FakeIoUtil) ReadDir(path string) ([]fs.DirEntry, error) {
|
||||
return util.FakeReadDir, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"os"
|
||||
)
|
||||
|
||||
@@ -49,6 +50,6 @@ type PluginRepo struct {
|
||||
type IoUtil interface {
|
||||
Stat(path string) (os.FileInfo, error)
|
||||
RemoveAll(path string) error
|
||||
ReadDir(path string) ([]os.FileInfo, error)
|
||||
ReadDir(path string) ([]fs.DirEntry, error)
|
||||
ReadFile(filename string) ([]byte, error)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"io/fs"
|
||||
"os"
|
||||
)
|
||||
|
||||
@@ -16,8 +16,8 @@ func (i IoUtilImp) RemoveAll(path string) error {
|
||||
return os.RemoveAll(path)
|
||||
}
|
||||
|
||||
func (i IoUtilImp) ReadDir(path string) ([]os.FileInfo, error) {
|
||||
return ioutil.ReadDir(path)
|
||||
func (i IoUtilImp) ReadDir(path string) ([]fs.DirEntry, error) {
|
||||
return os.ReadDir(path)
|
||||
}
|
||||
|
||||
func (i IoUtilImp) ReadFile(filename string) ([]byte, error) {
|
||||
|
||||
Reference in New Issue
Block a user