refactor: move to `filepath.WalkDir` for slight performance gain in Go 1.16 (#21858)
parent
865a030420
commit
c62d4cdc24
|
@ -39,10 +39,10 @@ func TestVerifies_Invalid(t *testing.T) {
|
|||
test := NewTest(t)
|
||||
defer os.RemoveAll(test.Path)
|
||||
|
||||
require.NoError(t, filepath.Walk(test.Path, func(path string, info os.FileInfo, err error) error {
|
||||
require.NoError(t, filepath.WalkDir(test.Path, func(path string, entry os.DirEntry, err error) error {
|
||||
require.NoError(t, err)
|
||||
|
||||
if info.IsDir() {
|
||||
if entry.IsDir() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ func NewVerifyTombstoneCommand() *cobra.Command {
|
|||
}
|
||||
|
||||
func (v *verifier) loadFiles() error {
|
||||
return filepath.Walk(v.path, func(path string, f os.FileInfo, err error) error {
|
||||
return filepath.WalkDir(v.path, func(path string, d os.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -151,7 +151,7 @@ func (v *verifyChecksums) run(cmd *cobra.Command, dataPath string, verbose bool)
|
|||
}
|
||||
|
||||
func (v *verifyTSM) loadFiles(dataPath string) error {
|
||||
err := filepath.Walk(dataPath, func(path string, f os.FileInfo, err error) error {
|
||||
err := filepath.WalkDir(dataPath, func(path string, d os.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -11,11 +11,15 @@ import (
|
|||
// DirSize returns total size in bytes of containing files
|
||||
func DirSize(path string) (uint64, error) {
|
||||
var size uint64
|
||||
err := filepath.Walk(path, func(_ string, info os.FileInfo, err error) error {
|
||||
err := filepath.WalkDir(path, func(_ string, entry os.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !info.IsDir() {
|
||||
if !entry.IsDir() {
|
||||
info, err := entry.Info()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
size += uint64(info.Size())
|
||||
}
|
||||
return err
|
||||
|
|
|
@ -48,7 +48,7 @@ type Test struct {
|
|||
}
|
||||
|
||||
func TestGoldenFiles(t *testing.T) {
|
||||
err := filepath.Walk("./goldenfiles", func(path string, info os.FileInfo, err error) error {
|
||||
err := filepath.WalkDir("./goldenfiles", func(path string, info os.DirEntry, err error) error {
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ func BoltFile() (string, error) {
|
|||
return "", err
|
||||
}
|
||||
var file string
|
||||
filepath.Walk(dir, func(p string, info os.FileInfo, err error) error {
|
||||
filepath.WalkDir(dir, func(p string, info os.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -24,13 +24,13 @@ func Stream(w io.Writer, dir, relativePath string, writeFunc func(f os.FileInfo,
|
|||
writeFunc = StreamFile
|
||||
}
|
||||
|
||||
return filepath.Walk(dir, func(path string, f os.FileInfo, err error) error {
|
||||
return filepath.WalkDir(dir, func(path string, entry os.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Skip adding an entry for the root dir
|
||||
if dir == path && f.IsDir() {
|
||||
if dir == path && entry.IsDir() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,10 @@ func Stream(w io.Writer, dir, relativePath string, writeFunc func(f os.FileInfo,
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
f, err := entry.Info()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return writeFunc(f, filepath.Join(relativePath, subDir), path, tw)
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue