forked from gen0cide/gscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (51 loc) · 1.14 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"os"
"path/filepath"
"github.com/karrick/godirwalk"
"github.com/pkg/errors"
"github.com/ahhh/gopkgs"
)
var (
packages = getPackages()
errSkipDir = errors.New("skipping this directory")
)
func getPackages() map[string]gopkgs.Pkg {
p, _ := gopkgs.Packages(gopkgs.Options{NoVendor: true})
switched := map[string]gopkgs.Pkg{}
for _, pkg := range p {
switched[pkg.Dir] = pkg
}
return switched
}
func walkWithNative(p string) error {
err := filepath.Walk(p, func(sp string, fi os.FileInfo, err error) error {
abspath, _ := filepath.Abs(sp)
if _, ok := packages[abspath]; ok {
return filepath.SkipDir
}
return nil
})
return err
}
func walkWithLib(p string) error {
err := godirwalk.Walk(p, &godirwalk.Options{
Callback: func(osp string, de *godirwalk.Dirent) error {
abspath, _ := filepath.Abs(osp)
if _, ok := packages[abspath]; ok {
return errSkipDir
}
return nil
},
ErrorCallback: func(d string, e error) godirwalk.ErrorAction {
if errors.Cause(e) == errSkipDir {
return godirwalk.SkipNode
}
return godirwalk.Halt
},
Unsorted: true,
})
return err
}
func main() {
}