Skip to content

Commit

Permalink
chore(action): speed up filesystem.DirTree
Browse files Browse the repository at this point in the history
- replace Walk with WalkDir

Signed-off-by: AtomicFS <vojtech.vesely@9elements.com>
  • Loading branch information
AtomicFS committed Dec 11, 2024
1 parent f1f9418 commit 81e0b94
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion action/filesystem/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ func MoveFile(pathSource, pathDestination string) error {
func DirTree(root string) ([]string, error) {
var files []string

err := filepath.Walk(root, func(path string, info os.FileInfo, _ error) error {
// WalkDir is faster than Walk
// https://pkg.go.dev/path/filepath#Walk
// > Walk is less efficient than WalkDir, introduced in Go 1.16, which avoids
// > calling os.Lstat on every visited file or directory.
err := filepath.WalkDir(root, func(path string, info os.DirEntry, _ error) error {
foundItem := path
if info.IsDir() {
foundItem = fmt.Sprintf("%s/", path)
Expand Down

0 comments on commit 81e0b94

Please sign in to comment.