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

Replace custom locking w/ mutexkv lib #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ go:
install:
- wget https://codeload.github.com/hashicorp/terraform/zip/v0.6.16 --no-check-certificate -O terraform-0.6.16.zip
- unzip terraform-0.6.16.zip
- mkdir $HOME/gopath/bin
- mkdir -p $HOME/gopath/bin
- mv terraform* $HOME/gopath/bin
- go get

Expand Down
22 changes: 8 additions & 14 deletions gitfile/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package gitfile

import (
"fmt"
"github.com/hashicorp/errwrap"
"github.com/hashicorp/terraform/helper/hashcode"
"os/exec"
"strings"
"sync"

"github.com/hashicorp/errwrap"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/mutexkv"
)

func gitCommand(checkout_dir string, args ...string) ([]byte, error) {
Expand Down Expand Up @@ -46,20 +47,13 @@ func hashString(v interface{}) int {
}
}

// map of checkout_dir to lock. file, commit, and checkout should grab the lock corresponding to a checkout dir
// around create/read/update/delete operations.
var checkoutLocks map[string]*sync.Mutex
// This is a global MutexKV for use within this plugin.
var gitfileMutexKV = mutexkv.NewMutexKV()

func lockCheckout(checkout_dir string) {
if checkoutLocks == nil {
checkoutLocks = map[string]*sync.Mutex{}
}
if checkoutLocks[checkout_dir] == nil {
checkoutLocks[checkout_dir] = new(sync.Mutex)
}
checkoutLocks[checkout_dir].Lock()
gitfileMutexKV.Lock(checkout_dir)
}

func unlockCheckout(checkout_dir string) {
checkoutLocks[checkout_dir].Unlock()
gitfileMutexKV.Unlock(checkout_dir)
}