Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 45126f4

Browse files
committedSep 21, 2017
internal/gps: export PruneProject and fix minor nits
Signed-off-by: Ibrahim AshShohail <[email protected]>
1 parent 20907fd commit 45126f4

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed
 

‎internal/gps/prune.go

+11-14
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package gps
66

77
import (
8-
"fmt"
98
"log"
109
"os"
1110
"path/filepath"
@@ -23,7 +22,8 @@ const (
2322
// PruneUnusedPackages indicates if unused Go packages should be pruned.
2423
PruneUnusedPackages
2524
// PruneNonGoFiles indicates if non-Go files should be pruned.
26-
// LICENSE & COPYING files are kept for convience.
25+
// Files matching licenseFilePrefixes and legalFileSubstrings are kept in
26+
// an attempt to comply with legal requirements.
2727
PruneNonGoFiles
2828
// PruneGoTestFiles indicates if Go test files should be pruned.
2929
PruneGoTestFiles
@@ -61,7 +61,7 @@ func Prune(baseDir string, options PruneOptions, l Lock, logger *log.Logger) err
6161
// TODO(ibrasho) allow passing specific options per project
6262
for _, lp := range l.Projects() {
6363
projectDir := filepath.Join(baseDir, string(lp.Ident().ProjectRoot))
64-
err := pruneProject(projectDir, lp, options, logger)
64+
err := PruneProject(projectDir, lp, options, logger)
6565
if err != nil {
6666
return err
6767
}
@@ -70,9 +70,9 @@ func Prune(baseDir string, options PruneOptions, l Lock, logger *log.Logger) err
7070
return nil
7171
}
7272

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

7878
if (options & PruneNestedVendorDirs) != 0 {
@@ -158,8 +158,8 @@ func calculateUnusedPackages(lp LockedProject, projectDir string) (map[string]st
158158
if err != nil {
159159
return errors.Wrap(err, "unexpected error while calculating unused packages")
160160
}
161-
fmt.Println(pkg)
162161

162+
filepath.ToSlash(pkg)
163163
if _, ok := imported[pkg]; !ok {
164164
unused[pkg] = struct{}{}
165165
}
@@ -174,7 +174,6 @@ func calculateUnusedPackages(lp LockedProject, projectDir string) (map[string]st
174174
func collectUnusedPackagesFiles(projectDir string, unusedPackages map[string]struct{}) ([]string, error) {
175175
// TODO(ibrasho): is this useful?
176176
files := make([]string, 0, len(unusedPackages))
177-
fmt.Println(unusedPackages)
178177

179178
err := filepath.Walk(projectDir, func(path string, info os.FileInfo, err error) error {
180179
if err != nil {
@@ -255,10 +254,8 @@ func collectNonGoFiles(baseDir string, logger *log.Logger) ([]string, error) {
255254
return files, err
256255
}
257256

258-
// isPreservedFile checks if the file name idicates that the file should be
259-
// preserved.
260-
// isPreservedFile checks if the file name contains one of the prefixes in
261-
// licenseFilePrefixes or contains one of the legalFileSubstrings entries.
257+
// isPreservedFile checks if the file name indicates that the file should be
258+
// preserved based on licenseFilePrefixes or legalFileSubstrings.
262259
func isPreservedFile(name string) bool {
263260
name = strings.ToLower(name)
264261

@@ -279,7 +276,7 @@ func isPreservedFile(name string) bool {
279276

280277
// pruneGoTestFiles deletes all Go test files (*_test.go) within baseDir.
281278
func pruneGoTestFiles(baseDir string, logger *log.Logger) error {
282-
files, err := collectGoTestsFile(baseDir)
279+
files, err := collectGoTestFiles(baseDir)
283280
if err != nil {
284281
return errors.Wrap(err, "could not collect Go test files")
285282
}
@@ -291,9 +288,9 @@ func pruneGoTestFiles(baseDir string, logger *log.Logger) error {
291288
return nil
292289
}
293290

294-
// collectGoTestsFile returns a slice contains all Go test files (any files
291+
// collectGoTestFiles returns a slice contains all Go test files (any files
295292
// prefixed with _test.go) in baseDir.
296-
func collectGoTestsFile(baseDir string) ([]string, error) {
293+
func collectGoTestFiles(baseDir string) ([]string, error) {
297294
files := make([]string, 0)
298295

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

0 commit comments

Comments
 (0)
This repository has been archived.