@@ -45,6 +45,10 @@ func Prune(baseDir string, l Lock, options PruneOptions, logger *log.Logger) err
45
45
}
46
46
}
47
47
48
+ if err := pruneEmptyDirs (baseDir , logger ); err != nil {
49
+ return errors .Wrap (err , "could not prune empty dirs" )
50
+ }
51
+
48
52
if (options & PruneUnusedPackages ) != 0 {
49
53
if l == nil {
50
54
return errors .New ("pruning unused packages requires passing non-nil Lock" )
@@ -54,17 +58,17 @@ func Prune(baseDir string, l Lock, options PruneOptions, logger *log.Logger) err
54
58
}
55
59
}
56
60
57
- // if (options & PruneNonGoFiles) != 0 {
58
- // if err := pruneNonGoFiles(baseDir, logger); err != nil {
59
- // return err
60
- // }
61
- // }
61
+ if (options & PruneNonGoFiles ) != 0 {
62
+ if err := pruneNonGoFiles (baseDir , logger ); err != nil {
63
+ return err
64
+ }
65
+ }
62
66
63
- // if (options & PruneGoTestFiles) != 0 {
64
- // if err := pruneGoTestFiles(baseDir, logger); err != nil {
65
- // return err
66
- // }
67
- // }
67
+ if (options & PruneGoTestFiles ) != 0 {
68
+ if err := pruneGoTestFiles (baseDir , logger ); err != nil {
69
+ return err
70
+ }
71
+ }
68
72
69
73
// Delete all empty directories.
70
74
return errors .Wrap (pruneEmptyDirs (baseDir , logger ), "could not prune empty dirs" )
@@ -85,7 +89,9 @@ func pruneUnusedPackages(baseDir string, l Lock, logger *log.Logger) error {
85
89
86
90
files , err := ioutil .ReadDir (pkgPath )
87
91
if err != nil {
88
- return err
92
+ // TODO(ibrasho) Handle this error properly.
93
+ // It happens when attempting to ioutil.ReadDir a submodule.
94
+ continue
89
95
}
90
96
91
97
// Delete *.go files in the package directory.
@@ -267,6 +273,8 @@ func pruneEmptyDirs(baseDir string, logger *log.Logger) error {
267
273
if logger != nil {
268
274
logger .Printf (" %s\n " , strings .TrimPrefix (dir , baseDir + string (os .PathSeparator )))
269
275
}
276
+ }
277
+ for _ , dir := range empty {
270
278
if err := os .Remove (dir ); err != nil {
271
279
return err
272
280
}
0 commit comments