Skip to content

Commit

Permalink
Merge pull request #36 from pote/fix/race_condition
Browse files Browse the repository at this point in the history
Prevents race conditions between dependencies (Fixes #35)
  • Loading branch information
Pablo Astigarraga committed Jun 5, 2014
2 parents a9efb66 + c4fb200 commit ca3c372
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions bin/gpm
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ USAGE
EOF
}

is_in_use() {
[[ -e "$1/.git/index.lock" || -e "$1/.hg/store/lock" || -e "$1/.bzr/checkout/lock" ]]
}

# Iterates over Godep file dependencies and sets
# the specified version on each of them.
set_dependencies() {
Expand All @@ -42,16 +46,20 @@ set_dependencies() {
while read package version; do
(
local install_path="${GOPATH%%:*}/src/${package%%/...}"
[[ -e "$install_path/.git/index.lock" ||
-e "$install_path/.hg/store/lock" ||
-e "$install_path/.bzr/checkout/lock" ]] && wait

echo ">> Getting package "$package""
go get -u -d "$package"

# Retries in case of possible race conditions when installing a package
# dependency
for ((i=0; i<5; i++)); do
out=$(go get -u -d "$package" 2>&1 >/dev/null) && break
done
[[ $? != 0 ]] && echo "-- Failed to get "$package", error: " && echo "$out" && exit 1

echo ">> Setting $package to version $version"
cd $install_path
[ -d .hg ] && hg update -q "$version"
is_in_use $install_path && wait

[ -d .hg ] && hg update -q "$version"
[ -d .git ] && git checkout -q "$version"
[ -d .bzr ] && bzr revert -q -r "$version"
[ -d .svn ] && svn update -r "$version"
Expand Down

0 comments on commit ca3c372

Please sign in to comment.