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

Fixes #1003 #1005

Merged
merged 1 commit into from
Aug 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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