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

Commit

Permalink
Merge pull request #1005 from ebati/fix-1003
Browse files Browse the repository at this point in the history
Fixes #1003
  • Loading branch information
sdboyer committed Aug 14, 2017
2 parents b0e3b27 + 814ee6b commit c0338b8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 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
2 changes: 1 addition & 1 deletion cmd/dep/prune_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestCalculatePrune(t *testing.T) {
filepath.FromSlash("github.com/keep/pkg/sub"),
}

got, err := calculatePrune(h.Path(vendorDir), toKeep, nil)
got, err := calculatePrune(h.Path(vendorDir), toKeep, discardLogger)
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit c0338b8

Please sign in to comment.