Skip to content

Commit 234e0e6

Browse files
committed
Fix the issue of taking a long time to search SMFix
1 parent e2f1322 commit 234e0e6

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func main() {
5555
}
5656

5757
if SmFixPath == "" {
58-
SmFixPath, _ = searchInDir("smfix", dir)
58+
SmFixPath, _ = searchInDir("smfix*", dir)
5959
}
6060
log.Println("SMFix:", SmFixPath)
6161

utils.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,18 @@ func searchInDir(exp string, dirpath string) (abspath string, err error) {
3838

3939
// check if the dir is a symbolic link
4040
if dirInfo.Mode()&os.ModeSymlink != 0 {
41-
dirpath, err = os.Readlink(dirpath)
41+
dirpath, _ = os.Readlink(dirpath)
4242
}
4343

44-
err = filepath.Walk(dirpath, func(path string, info os.FileInfo, err error) error {
45-
if err != nil {
46-
return err
44+
if found, err := filepath.Glob(filepath.Join(dirpath, exp)); err == nil {
45+
for _, file := range found {
46+
if stat, err := os.Stat(file); err == nil && !stat.IsDir() && stat.Mode().Perm()&0100 != 0 {
47+
abspath = file
48+
return abspath, nil
49+
}
4750
}
48-
if !info.IsDir() && filepath.HasPrefix(info.Name(), exp) {
49-
abspath = path
50-
return nil
51-
}
52-
return nil
53-
})
51+
}
52+
5453
return abspath, err
5554
}
5655

0 commit comments

Comments
 (0)