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

Commit 30ba901

Browse files
committed
dep: update calculatePrune to not assume "/" as separtor
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]>
1 parent 0584d8c commit 30ba901

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

txn_writer.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ fail:
530530
return failerr
531531
}
532532

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

550-
name := strings.TrimPrefix(path, vendorDir+"/")
551+
name := strings.TrimPrefix(path, vendorDir+string(filepath.Separator))
551552
if logger != nil {
552553
logger.Printf(" %s", name)
553554
}

txn_writer_test.go

+8-10
Original file line numberDiff line numberDiff line change
@@ -577,11 +577,12 @@ func TestCalculatePrune(t *testing.T) {
577577

578578
vendorDir := "vendor"
579579
h.TempDir(vendorDir)
580-
h.TempDir(filepath.Join(vendorDir, "github.com", "prune", "package"))
581-
h.TempDir(filepath.Join(vendorDir, "github.com", "keep", "package"))
580+
h.TempDir(filepath.Join(vendorDir, "github.com/keep/pkg/sub"))
581+
h.TempDir(filepath.Join(vendorDir, "github.com/prune/pkg/sub"))
582582

583583
toKeep := []string{
584-
"github.com/keep/package",
584+
filepath.FromSlash("github.com/keep/pkg"),
585+
filepath.FromSlash("github.com/keep/pkg/sub"),
585586
}
586587

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

592593
sort.Sort(byLen(got))
593594

594-
if len(got) != 2 {
595-
t.Fatalf("expected 2 directories, got %v", len(got))
596-
}
597-
598595
want := []string{
599-
h.Path(filepath.Join(vendorDir, "github.com", "prune", "package")),
600-
h.Path(filepath.Join(vendorDir, "github.com", "prune")),
596+
h.Path(filepath.Join(vendorDir, "github.com/prune/pkg/sub")),
597+
h.Path(filepath.Join(vendorDir, "github.com/prune/pkg")),
598+
h.Path(filepath.Join(vendorDir, "github.com/prune")),
601599
}
602600

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

0 commit comments

Comments
 (0)