Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
Fixes #1003
Browse files Browse the repository at this point in the history
  • Loading branch information
ebati committed Aug 13, 2017
1 parent d13e867 commit 2282d68
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions cmd/dep/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ func (cmd *pruneCommand) Run(ctx *dep.Ctx, args []string) error {
return errors.Errorf("Gopkg.lock is out of sync; run dep ensure before pruning.")
}

var pruneLogger *log.Logger
if ctx.Verbose {
pruneLogger = ctx.Err
pruneLogger := ctx.Err
if !ctx.Verbose {
pruneLogger = log.New(ioutil.Discard, "", 0)
}
return pruneProject(p, sm, pruneLogger)
}
Expand Down Expand Up @@ -114,15 +114,13 @@ func pruneProject(p *dep.Project, sm gps.SourceManager, logger *log.Logger) erro
return err
}

if logger != nil {
if len(toDelete) > 0 {
logger.Println("Calculated the following directories to prune:")
for _, d := range toDelete {
logger.Printf(" %s\n", d)
}
} else {
logger.Println("No directories found to prune")
if len(toDelete) > 0 {
logger.Println("Calculated the following directories to prune:")
for _, d := range toDelete {
logger.Printf(" %s\n", d)
}
} else {
logger.Println("No directories found to prune")
}

if err := deleteDirs(toDelete); err != nil {
Expand Down Expand Up @@ -163,9 +161,7 @@ fail:
}

func calculatePrune(vendorDir string, keep []string, logger *log.Logger) ([]string, error) {
if logger != nil {
logger.Println("Calculating prune. Checking the following packages:")
}
logger.Println("Calculating prune. Checking the following packages:")
sort.Strings(keep)
toDelete := []string{}
err := filepath.Walk(vendorDir, func(path string, info os.FileInfo, err error) error {
Expand All @@ -180,9 +176,7 @@ func calculatePrune(vendorDir string, keep []string, logger *log.Logger) ([]stri
}

name := strings.TrimPrefix(path, vendorDir+string(filepath.Separator))
if logger != nil {
logger.Printf(" %s", name)
}
logger.Printf(" %s", name)
i := sort.Search(len(keep), func(i int) bool {
return name <= keep[i]
})
Expand Down

0 comments on commit 2282d68

Please sign in to comment.