-
Notifications
You must be signed in to change notification settings - Fork 538
/
strip.go
53 lines (43 loc) · 1.04 KB
/
strip.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
package path
import (
"os"
"path/filepath"
"github.com/Masterminds/glide/godep/strip"
"github.com/Masterminds/glide/msg"
)
func getWalkFunction(searchPath string, removeAll func(p string) error) func(path string,
info os.FileInfo, err error) error {
return func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
// Skip the base vendor directory
if path == searchPath {
return nil
}
if info.Name() == "vendor" && info.IsDir() {
msg.Info("Removing: %s", path)
err = removeAll(path)
if nil != err {
return err
}
return filepath.SkipDir
}
return nil
}
}
// StripVendor removes nested vendor and Godeps/_workspace/ directories.
func StripVendor() error {
searchPath, _ := Vendor()
if _, err := os.Stat(searchPath); err != nil {
if os.IsNotExist(err) {
msg.Debug("Vendor directory does not exist.")
}
return err
}
err := filepath.Walk(searchPath, getWalkFunction(searchPath, CustomRemoveAll))
if err != nil {
return err
}
return strip.GodepWorkspace(searchPath)
}