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

Commit 9b6892c

Browse files
committed
internal/gps: export PruneProject and fix minor nits
Signed-off-by: Ibrahim AshShohail <[email protected]>
1 parent 98dd01e commit 9b6892c

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

internal/gps/prune.go

+12-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+
pkg = 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 {
@@ -196,6 +195,7 @@ func collectUnusedPackagesFiles(projectDir string, unusedPackages map[string]str
196195
return errors.Wrap(err, "unexpected error while calculating unused packages")
197196
}
198197

198+
pkg = filepath.ToSlash(pkg)
199199
if _, ok := unusedPackages[pkg]; ok {
200200
files = append(files, path)
201201
}
@@ -255,10 +255,8 @@ func collectNonGoFiles(baseDir string, logger *log.Logger) ([]string, error) {
255255
return files, err
256256
}
257257

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.
258+
// isPreservedFile checks if the file name indicates that the file should be
259+
// preserved based on licenseFilePrefixes or legalFileSubstrings.
262260
func isPreservedFile(name string) bool {
263261
name = strings.ToLower(name)
264262

@@ -279,7 +277,7 @@ func isPreservedFile(name string) bool {
279277

280278
// pruneGoTestFiles deletes all Go test files (*_test.go) within baseDir.
281279
func pruneGoTestFiles(baseDir string, logger *log.Logger) error {
282-
files, err := collectGoTestsFile(baseDir)
280+
files, err := collectGoTestFiles(baseDir)
283281
if err != nil {
284282
return errors.Wrap(err, "could not collect Go test files")
285283
}
@@ -291,9 +289,9 @@ func pruneGoTestFiles(baseDir string, logger *log.Logger) error {
291289
return nil
292290
}
293291

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

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

0 commit comments

Comments
 (0)