Skip to content

Commit

Permalink
refactor: move to filepath.WalkDir for slight performance gain in G…
Browse files Browse the repository at this point in the history
…o 1.16 (influxdata#21858)
  • Loading branch information
serenibyss authored Jul 16, 2021
1 parent 865a030 commit c62d4cd
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/influxd/inspect/verify_tombstone/verify_tombstone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/influxd/inspect/verify_tsm/verify_tsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 6 additions & 2 deletions cmd/influxd/upgrade/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion influxql/v1validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion internal/fs/influx_dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/tar/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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)
})
Expand Down

0 comments on commit c62d4cd

Please sign in to comment.