This commit is contained in:
Jonathan Stacks 2017-05-22 22:05:21 -05:00
Родитель e241dcf295
Коммит 5af30944ef
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 88F902E863083DCA
2 изменённых файлов: 24 добавлений и 4 удалений

Просмотреть файл

@ -7,6 +7,7 @@ package main
import ( import (
"bytes" "bytes"
"flag" "flag"
"log"
"github.com/golang/dep" "github.com/golang/dep"
"github.com/golang/dep/internal/gps" "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 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)
} }

Просмотреть файл

@ -495,7 +495,7 @@ func (sw *SafeWriter) PrintPreparedActions(output *log.Logger) error {
return nil 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") td, err := ioutil.TempDir(os.TempDir(), "dep")
if err != nil { if err != nil {
return errors.Wrap(err, "error while creating temp dir for writing manifest/lock/vendor") 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 { if err != nil {
return err 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 { if err := deleteDirs(toDelete); err != nil {
return err return err
} }
@ -556,7 +565,10 @@ fail:
return failerr 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) sort.Strings(keep)
toDelete := []string{} toDelete := []string{}
err := filepath.Walk(vendorDir, func(path string, info os.FileInfo, err error) error { 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+"/") name := strings.TrimPrefix(path, vendorDir+"/")
if logger != nil {
logger.Printf(" %s", name)
}
i := sort.Search(len(keep), func(i int) bool { i := sort.Search(len(keep), func(i int) bool {
return name <= keep[i] return name <= keep[i]
}) })