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

Commit

Permalink
dep: update calculatePrune to not assume "/" as separtor
Browse files Browse the repository at this point in the history
dep.calculatePrune assumes "/" is the file separtor. This change fixes
an issue caused by that on Windows.

Fixes #775

Signed-off-by: Ibrahim AshShohail <[email protected]>
  • Loading branch information
ibrasho committed Jun 22, 2017
1 parent 0584d8c commit a2f09dc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
3 changes: 2 additions & 1 deletion txn_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ fail:
return failerr
}

// calculatePrune returns the paths of the packages to be deleted from vendorDir.
func calculatePrune(vendorDir string, keep []string, logger *log.Logger) ([]string, error) {
if logger != nil {
logger.Println("Calculating prune. Checking the following packages:")
Expand All @@ -547,7 +548,7 @@ func calculatePrune(vendorDir string, keep []string, logger *log.Logger) ([]stri
return nil
}

name := strings.TrimPrefix(path, vendorDir+"/")
name := strings.TrimPrefix(path, vendorDir+string(filepath.Separator))
if logger != nil {
logger.Printf(" %s", name)
}
Expand Down
18 changes: 8 additions & 10 deletions txn_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,11 +577,12 @@ func TestCalculatePrune(t *testing.T) {

vendorDir := "vendor"
h.TempDir(vendorDir)
h.TempDir(filepath.Join(vendorDir, "github.com", "prune", "package"))
h.TempDir(filepath.Join(vendorDir, "github.com", "keep", "package"))
h.TempDir(filepath.Join(vendorDir, "github.com/keep/pkg/sub"))
h.TempDir(filepath.Join(vendorDir, "github.com/prune/pkg/sub"))

toKeep := []string{
"github.com/keep/package",
filepath.FromSlash("github.com/keep/pkg"),
filepath.FromSlash("github.com/keep/pkg/sub"),
}

got, err := calculatePrune(h.Path(vendorDir), toKeep, nil)
Expand All @@ -591,16 +592,13 @@ func TestCalculatePrune(t *testing.T) {

sort.Sort(byLen(got))

if len(got) != 2 {
t.Fatalf("expected 2 directories, got %v", len(got))
}

want := []string{
h.Path(filepath.Join(vendorDir, "github.com", "prune", "package")),
h.Path(filepath.Join(vendorDir, "github.com", "prune")),
h.Path(filepath.Join(vendorDir, "github.com/prune/pkg/sub")),
h.Path(filepath.Join(vendorDir, "github.com/prune/pkg")),
h.Path(filepath.Join(vendorDir, "github.com/prune")),
}

if !reflect.DeepEqual(want, got) {
t.Fatalf("expect %s, got %s", want, got)
t.Fatalf("calculated prune paths are not as expected.\n(WNT) %s\n(GOT) %s", want, got)
}
}

0 comments on commit a2f09dc

Please sign in to comment.