Skip to content

Commit

Permalink
[preprocessor/folder] use filepath.WalkDir instead of filepath.Walk
Browse files Browse the repository at this point in the history
  • Loading branch information
williamchong committed May 31, 2024
1 parent 6aebf96 commit 9fabac2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
4 changes: 1 addition & 3 deletions preprocessor/folder/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package folder

import (
"fmt"
"io/fs"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -59,9 +58,8 @@ func handleNewFile(filePath string) (string, error) {
}

// shouldIncludeFile reports whether the file should be included in the processing
func shouldIncludeFile(info fs.FileInfo) bool {
func shouldIncludeFile(fileName string) bool {
whiteListExtension := config.GetConfig().FolderPreprocessor.FileExtensions
fileName := info.Name()
if fileName[0] == '.' {
return false
}
Expand Down
6 changes: 3 additions & 3 deletions preprocessor/folder/folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ func scanSyncDirectory(subPath string) ([]string, error) {
}
scanPath := filepath.Join(scanRoot, subPath)
fileList := []string{}
err := filepath.Walk(scanPath, func(path string, info fs.FileInfo, err error) error {
err := filepath.WalkDir(scanPath, func(path string, info os.DirEntry, err error) error {
if err != nil {
return err
}
if shouldIncludeFile(info) {
if shouldIncludeFile(info.Name()) {
fileList = append(fileList, path)
fmt.Println("Found: " + path)
return nil
Expand Down Expand Up @@ -73,7 +73,7 @@ func Run(args []string) error {
fmt.Println("error getting file info:", err)
continue
}
if shouldIncludeFile(fileInfo) {
if shouldIncludeFile(fileInfo.Name()) {
cid, err := handleNewFile(filePath)
if err != nil {
fmt.Println(err)
Expand Down

0 comments on commit 9fabac2

Please sign in to comment.