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

Commit

Permalink
internal/gps: export PruneProject and fix minor nits
Browse files Browse the repository at this point in the history
Signed-off-by: Ibrahim AshShohail <[email protected]>
  • Loading branch information
ibrasho committed Sep 9, 2017
1 parent 20907fd commit bc90972
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions internal/gps/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package gps

import (
"fmt"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -70,9 +69,9 @@ func Prune(baseDir string, options PruneOptions, l Lock, logger *log.Logger) err
return nil
}

// pruneProject remove excess files according to the options passed, from
// PruneProject remove excess files according to the options passed, from
// the lp directory in baseDir.
func pruneProject(baseDir string, lp LockedProject, options PruneOptions, logger *log.Logger) error {
func PruneProject(baseDir string, lp LockedProject, options PruneOptions, logger *log.Logger) error {
projectDir := filepath.Join(baseDir, string(lp.Ident().ProjectRoot))

if (options & PruneNestedVendorDirs) != 0 {
Expand Down Expand Up @@ -158,7 +157,6 @@ func calculateUnusedPackages(lp LockedProject, projectDir string) (map[string]st
if err != nil {
return errors.Wrap(err, "unexpected error while calculating unused packages")
}
fmt.Println(pkg)

if _, ok := imported[pkg]; !ok {
unused[pkg] = struct{}{}
Expand All @@ -174,7 +172,6 @@ func calculateUnusedPackages(lp LockedProject, projectDir string) (map[string]st
func collectUnusedPackagesFiles(projectDir string, unusedPackages map[string]struct{}) ([]string, error) {
// TODO(ibrasho): is this useful?
files := make([]string, 0, len(unusedPackages))
fmt.Println(unusedPackages)

err := filepath.Walk(projectDir, func(path string, info os.FileInfo, err error) error {
if err != nil {
Expand Down Expand Up @@ -256,9 +253,7 @@ func collectNonGoFiles(baseDir string, logger *log.Logger) ([]string, error) {
}

// isPreservedFile checks if the file name idicates that the file should be
// preserved.
// isPreservedFile checks if the file name contains one of the prefixes in
// licenseFilePrefixes or contains one of the legalFileSubstrings entries.
// preserved based on licenseFilePrefixes or legalFileSubstrings.
func isPreservedFile(name string) bool {
name = strings.ToLower(name)

Expand All @@ -279,7 +274,7 @@ func isPreservedFile(name string) bool {

// pruneGoTestFiles deletes all Go test files (*_test.go) within baseDir.
func pruneGoTestFiles(baseDir string, logger *log.Logger) error {
files, err := collectGoTestsFile(baseDir)
files, err := collectGoTestFiles(baseDir)
if err != nil {
return errors.Wrap(err, "could not collect Go test files")
}
Expand All @@ -291,9 +286,9 @@ func pruneGoTestFiles(baseDir string, logger *log.Logger) error {
return nil
}

// collectGoTestsFile returns a slice contains all Go test files (any files
// collectGoTestFiles returns a slice contains all Go test files (any files
// prefixed with _test.go) in baseDir.
func collectGoTestsFile(baseDir string) ([]string, error) {
func collectGoTestFiles(baseDir string) ([]string, error) {
files := make([]string, 0)

err := filepath.Walk(baseDir, func(path string, info os.FileInfo, err error) error {
Expand Down

0 comments on commit bc90972

Please sign in to comment.