@@ -22,7 +22,6 @@ import (
22
22
"github.com/golang/dep/internal/gps/paths"
23
23
"github.com/golang/dep/internal/gps/pkgtree"
24
24
"github.com/pkg/errors"
25
- "golang.org/x/sync/syncmap"
26
25
)
27
26
28
27
const ensureShortHelp = `Ensure a dependency is safely vendored in the project`
@@ -470,9 +469,10 @@ func (cmd *ensureCommand) runAdd(ctx *dep.Ctx, args []string, p *dep.Project, sm
470
469
constraint gps.Constraint
471
470
typ addType
472
471
}
472
+ addInstructions := make (map [gps.ProjectRoot ]addInstruction )
473
473
474
- // Create a syncmap to store all the addInstruction(s) concurrently .
475
- addInstructions := new (syncmap. Map )
474
+ // A mutex for limited access to addInstructions by goroutines .
475
+ var mutex sync. Mutex
476
476
477
477
// Channel for receiving all the errors.
478
478
errCh := make (chan error , len (args ))
@@ -519,8 +519,9 @@ func (cmd *ensureCommand) runAdd(ctx *dep.Ctx, args []string, p *dep.Project, sm
519
519
520
520
someConstraint := ! gps .IsAny (pc .Constraint ) || pc .Ident .Source != ""
521
521
522
- instrInterface , has := addInstructions .LoadOrStore (pc .Ident .ProjectRoot , addInstruction {})
523
- instr := instrInterface .(addInstruction )
522
+ // Obtain a lock for addInstructions
523
+ mutex .Lock ()
524
+ instr , has := addInstructions [pc .Ident .ProjectRoot ]
524
525
if has {
525
526
// Multiple packages from the same project were specified as
526
527
// arguments; make sure they agree on declared constraints.
@@ -575,7 +576,8 @@ func (cmd *ensureCommand) runAdd(ctx *dep.Ctx, args []string, p *dep.Project, sm
575
576
instr .ephReq [path ] = true
576
577
}
577
578
578
- addInstructions .Store (pc .Ident .ProjectRoot , instr )
579
+ addInstructions [pc .Ident .ProjectRoot ] = instr
580
+ mutex .Unlock ()
579
581
}(arg )
580
582
}
581
583
@@ -597,9 +599,7 @@ func (cmd *ensureCommand) runAdd(ctx *dep.Ctx, args []string, p *dep.Project, sm
597
599
598
600
// We're now sure all of our add instructions are individually and mutually
599
601
// valid, so it's safe to begin modifying the input parameters.
600
- addInstructions .Range (func (ki , vi interface {}) bool {
601
- pr := ki .(gps.ProjectRoot )
602
- instr := vi .(addInstruction )
602
+ for pr , instr := range addInstructions {
603
603
// The arg processing logic above only adds to the ephReq list if
604
604
// that package definitely needs to be on that list, so we don't
605
605
// need to check instr.typ here - if it's in instr.ephReq, it
@@ -616,9 +616,7 @@ func (cmd *ensureCommand) runAdd(ctx *dep.Ctx, args []string, p *dep.Project, sm
616
616
Constraint : instr .constraint ,
617
617
}
618
618
}
619
-
620
- return true
621
- })
619
+ }
622
620
623
621
// Re-prepare a solver now that our params are complete.
624
622
solver , err = gps .Prepare (params , sm )
@@ -636,10 +634,7 @@ func (cmd *ensureCommand) runAdd(ctx *dep.Ctx, args []string, p *dep.Project, sm
636
634
var reqlist []string
637
635
appender := dep .NewManifest ()
638
636
639
- addInstructions .Range (func (ki , vi interface {}) bool {
640
- pr := ki .(gps.ProjectRoot )
641
- instr := vi .(addInstruction )
642
-
637
+ for pr , instr := range addInstructions {
643
638
for path := range instr .ephReq {
644
639
reqlist = append (reqlist , path )
645
640
}
@@ -667,9 +662,7 @@ func (cmd *ensureCommand) runAdd(ctx *dep.Ctx, args []string, p *dep.Project, sm
667
662
}
668
663
appender .Constraints [pr ] = pp
669
664
}
670
-
671
- return true
672
- })
665
+ }
673
666
674
667
extra , err := appender .MarshalTOML ()
675
668
if err != nil {
0 commit comments