From 613a6cfc607af8470ceec5b7391f9231fa1f98dd Mon Sep 17 00:00:00 2001 From: gofastasf Date: Fri, 24 Jan 2025 03:03:41 +0530 Subject: [PATCH] Optimize/directory traversal (#2970) --- .changelog/67431bb2-f939-4912-b813-adcc349a4bf5.json | 9 +++++++++ internal/ini/ini_test.go | 7 ++++--- internal/repotools/cmd/syncAPIModels/main.go | 9 +++++---- 3 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 .changelog/67431bb2-f939-4912-b813-adcc349a4bf5.json diff --git a/.changelog/67431bb2-f939-4912-b813-adcc349a4bf5.json b/.changelog/67431bb2-f939-4912-b813-adcc349a4bf5.json new file mode 100644 index 00000000000..f98ce5c2963 --- /dev/null +++ b/.changelog/67431bb2-f939-4912-b813-adcc349a4bf5.json @@ -0,0 +1,9 @@ +{ + "id": "67431bb2-f939-4912-b813-adcc349a4bf5", + "type": "Announcement", + "description": "Refactor filepath.Walk to filepath.WalkDir", + "collapse": false, + "modules": [ + "internal/ini" + ] +} \ No newline at end of file diff --git a/internal/ini/ini_test.go b/internal/ini/ini_test.go index 92c7e2007bd..68837e6dc37 100644 --- a/internal/ini/ini_test.go +++ b/internal/ini/ini_test.go @@ -3,6 +3,7 @@ package ini import ( "encoding/json" "fmt" + "io/fs" "io/ioutil" "os" "path/filepath" @@ -12,13 +13,13 @@ import ( func TestValidDataFiles(t *testing.T) { const expectedFileSuffix = "_expected" - err := filepath.Walk(filepath.Join("testdata", "valid"), - func(path string, info os.FileInfo, fnErr error) (err error) { + err := filepath.WalkDir(filepath.Join("testdata", "valid"), + func(path string, d fs.DirEntry, fnErr error) (err error) { if strings.HasSuffix(path, expectedFileSuffix) { return nil } - if info.IsDir() { + if d.IsDir() { return nil } diff --git a/internal/repotools/cmd/syncAPIModels/main.go b/internal/repotools/cmd/syncAPIModels/main.go index 6b8e4ff2ff6..cfbb66ed93d 100644 --- a/internal/repotools/cmd/syncAPIModels/main.go +++ b/internal/repotools/cmd/syncAPIModels/main.go @@ -5,6 +5,7 @@ import ( "flag" "fmt" "io" + "io/fs" "log" "os" "path/filepath" @@ -74,13 +75,13 @@ type SourceModel struct { func findSmithyModels(modelPath string) (map[string]SourceModel, error) { models := map[string]SourceModel{} - err := filepath.Walk(modelPath, - func(path string, info os.FileInfo, err error) error { - if err != nil || info.IsDir() { + err := filepath.WalkDir(modelPath, + func(path string, d fs.DirEntry, err error) error { + if err != nil || d.IsDir() { return err } - if filepath.Ext(info.Name()) != ".json" { + if filepath.Ext(d.Name()) != ".json" { return nil }