From d762e3c1921ab1e38960ac31e4f78290a9e29afb Mon Sep 17 00:00:00 2001 From: Ibrahim AshShohail Date: Mon, 7 Aug 2017 22:51:21 +0300 Subject: [PATCH] one more Signed-off-by: Ibrahim AshShohail --- internal/gps/prune.go | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/internal/gps/prune.go b/internal/gps/prune.go index 4273f3eba8..4b74265a8b 100644 --- a/internal/gps/prune.go +++ b/internal/gps/prune.go @@ -45,6 +45,10 @@ func Prune(baseDir string, l Lock, options PruneOptions, logger *log.Logger) err } } + if err := pruneEmptyDirs(baseDir, logger); err != nil { + return errors.Wrap(err, "could not prune empty dirs") + } + if (options & PruneUnusedPackages) != 0 { if l == nil { 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 } } - // if (options & PruneNonGoFiles) != 0 { - // if err := pruneNonGoFiles(baseDir, logger); err != nil { - // return err - // } - // } + if (options & PruneNonGoFiles) != 0 { + if err := pruneNonGoFiles(baseDir, logger); err != nil { + return err + } + } - // if (options & PruneGoTestFiles) != 0 { - // if err := pruneGoTestFiles(baseDir, logger); err != nil { - // return err - // } - // } + if (options & PruneGoTestFiles) != 0 { + if err := pruneGoTestFiles(baseDir, logger); err != nil { + return err + } + } // Delete all empty directories. 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 { files, err := ioutil.ReadDir(pkgPath) if err != nil { - return err + // TODO(ibrasho) Handle this error properly. + // It happens when attempting to ioutil.ReadDir a submodule. + continue } // Delete *.go files in the package directory. @@ -267,6 +273,8 @@ func pruneEmptyDirs(baseDir string, logger *log.Logger) error { if logger != nil { logger.Printf(" %s\n", strings.TrimPrefix(dir, baseDir+string(os.PathSeparator))) } + } + for _, dir := range empty { if err := os.Remove(dir); err != nil { return err }