Skip to content

Commit

Permalink
Synchronize access to artifact map to remove race
Browse files Browse the repository at this point in the history
  • Loading branch information
markpeek committed Oct 14, 2015
1 parent d1f9a46 commit af055ad
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions command/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ func (c BuildCommand) Run(args []string) int {
// Run all the builds in parallel and wait for them to complete
var interruptWg, wg sync.WaitGroup
interrupted := false
artifacts := make(map[string][]packer.Artifact)
var artifacts = struct {
sync.RWMutex
m map[string][]packer.Artifact
}{m: make(map[string][]packer.Artifact)}
errors := make(map[string]error)
for _, b := range builds {
// Increment the waitgroup so we wait for this item to finish properly
Expand Down Expand Up @@ -163,7 +166,9 @@ func (c BuildCommand) Run(args []string) int {
errors[name] = err
} else {
ui.Say(fmt.Sprintf("Build '%s' finished.", name))
artifacts[name] = runArtifacts
artifacts.Lock()
artifacts.m[name] = runArtifacts
artifacts.Unlock()
}
}(b)

Expand Down Expand Up @@ -213,9 +218,9 @@ func (c BuildCommand) Run(args []string) int {
}
}

if len(artifacts) > 0 {
if len(artifacts.m) > 0 {
c.Ui.Say("\n==> Builds finished. The artifacts of successful builds are:")
for name, buildArtifacts := range artifacts {
for name, buildArtifacts := range artifacts.m {
// Create a UI for the machine readable stuff to be targetted
ui := &packer.TargettedUi{
Target: name,
Expand Down

0 comments on commit af055ad

Please sign in to comment.