Skip to content

Commit 613a6cf

Browse files
authored
Optimize/directory traversal (#2970)
1 parent c47fe24 commit 613a6cf

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"id": "67431bb2-f939-4912-b813-adcc349a4bf5",
3+
"type": "Announcement",
4+
"description": "Refactor filepath.Walk to filepath.WalkDir",
5+
"collapse": false,
6+
"modules": [
7+
"internal/ini"
8+
]
9+
}

internal/ini/ini_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package ini
33
import (
44
"encoding/json"
55
"fmt"
6+
"io/fs"
67
"io/ioutil"
78
"os"
89
"path/filepath"
@@ -12,13 +13,13 @@ import (
1213

1314
func TestValidDataFiles(t *testing.T) {
1415
const expectedFileSuffix = "_expected"
15-
err := filepath.Walk(filepath.Join("testdata", "valid"),
16-
func(path string, info os.FileInfo, fnErr error) (err error) {
16+
err := filepath.WalkDir(filepath.Join("testdata", "valid"),
17+
func(path string, d fs.DirEntry, fnErr error) (err error) {
1718
if strings.HasSuffix(path, expectedFileSuffix) {
1819
return nil
1920
}
2021

21-
if info.IsDir() {
22+
if d.IsDir() {
2223
return nil
2324
}
2425

internal/repotools/cmd/syncAPIModels/main.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"flag"
66
"fmt"
77
"io"
8+
"io/fs"
89
"log"
910
"os"
1011
"path/filepath"
@@ -74,13 +75,13 @@ type SourceModel struct {
7475
func findSmithyModels(modelPath string) (map[string]SourceModel, error) {
7576
models := map[string]SourceModel{}
7677

77-
err := filepath.Walk(modelPath,
78-
func(path string, info os.FileInfo, err error) error {
79-
if err != nil || info.IsDir() {
78+
err := filepath.WalkDir(modelPath,
79+
func(path string, d fs.DirEntry, err error) error {
80+
if err != nil || d.IsDir() {
8081
return err
8182
}
8283

83-
if filepath.Ext(info.Name()) != ".json" {
84+
if filepath.Ext(d.Name()) != ".json" {
8485
return nil
8586
}
8687

0 commit comments

Comments
 (0)