From 5af30944efe6636273df71cade86111281c8ecd8 Mon Sep 17 00:00:00 2001 From: Jonathan Stacks Date: Mon, 22 May 2017 22:05:21 -0500 Subject: [PATCH] Add some logging to dep prune --- cmd/dep/prune.go | 7 ++++++- txn_writer.go | 21 ++++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/cmd/dep/prune.go b/cmd/dep/prune.go index 75e9a2e1..c49b1a32 100644 --- a/cmd/dep/prune.go +++ b/cmd/dep/prune.go @@ -7,6 +7,7 @@ package main import ( "bytes" "flag" + "log" "github.com/golang/dep" "github.com/golang/dep/internal/gps" @@ -75,5 +76,9 @@ func (cmd *pruneCommand) Run(ctx *dep.Ctx, args []string) error { return errors.Errorf("lock hash doesn't match") } - return dep.PruneProject(p, sm) + var pruneLogger *log.Logger + if ctx.Loggers.Verbose { + pruneLogger = ctx.Loggers.Err + } + return dep.PruneProject(p, sm, pruneLogger) } diff --git a/txn_writer.go b/txn_writer.go index c252c134..a476d186 100644 --- a/txn_writer.go +++ b/txn_writer.go @@ -495,7 +495,7 @@ func (sw *SafeWriter) PrintPreparedActions(output *log.Logger) error { return nil } -func PruneProject(p *Project, sm gps.SourceManager) error { +func PruneProject(p *Project, sm gps.SourceManager, logger *log.Logger) error { td, err := ioutil.TempDir(os.TempDir(), "dep") if err != nil { return errors.Wrap(err, "error while creating temp dir for writing manifest/lock/vendor") @@ -514,11 +514,20 @@ func PruneProject(p *Project, sm gps.SourceManager) error { } } - toDelete, err := calculatePrune(td, toKeep) + toDelete, err := calculatePrune(td, toKeep, logger) if err != nil { return err } + if logger != nil { + if len(toDelete) > 0 { + logger.Println("Calculated the following directories to prune:") + for _, d := range toDelete { + logger.Printf(" %s", d) + } + } + } + if err := deleteDirs(toDelete); err != nil { return err } @@ -556,7 +565,10 @@ fail: return failerr } -func calculatePrune(vendorDir string, keep []string) ([]string, error) { +func calculatePrune(vendorDir string, keep []string, logger *log.Logger) ([]string, error) { + if logger != nil { + 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 { @@ -571,6 +583,9 @@ func calculatePrune(vendorDir string, keep []string) ([]string, error) { } name := strings.TrimPrefix(path, vendorDir+"/") + if logger != nil { + logger.Printf(" %s", name) + } i := sort.Search(len(keep), func(i int) bool { return name <= keep[i] })