Skip to content

Commit

Permalink
Optimize/directory traversal (#2970)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gofastasf authored Jan 23, 2025
1 parent c47fe24 commit 613a6cf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
9 changes: 9 additions & 0 deletions .changelog/67431bb2-f939-4912-b813-adcc349a4bf5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"id": "67431bb2-f939-4912-b813-adcc349a4bf5",
"type": "Announcement",
"description": "Refactor filepath.Walk to filepath.WalkDir",
"collapse": false,
"modules": [
"internal/ini"
]
}
7 changes: 4 additions & 3 deletions internal/ini/ini_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ini
import (
"encoding/json"
"fmt"
"io/fs"
"io/ioutil"
"os"
"path/filepath"
Expand All @@ -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
}

Expand Down
9 changes: 5 additions & 4 deletions internal/repotools/cmd/syncAPIModels/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"flag"
"fmt"
"io"
"io/fs"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 613a6cf

Please sign in to comment.