Skip to content

Commit ca3c372

Browse files
author
Pablo Astigarraga
committed
Merge pull request #36 from pote/fix/race_condition
Prevents race conditions between dependencies (Fixes #35)
2 parents a9efb66 + c4fb200 commit ca3c372

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

bin/gpm

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ USAGE
3434
EOF
3535
}
3636

37+
is_in_use() {
38+
[[ -e "$1/.git/index.lock" || -e "$1/.hg/store/lock" || -e "$1/.bzr/checkout/lock" ]]
39+
}
40+
3741
# Iterates over Godep file dependencies and sets
3842
# the specified version on each of them.
3943
set_dependencies() {
@@ -42,16 +46,20 @@ set_dependencies() {
4246
while read package version; do
4347
(
4448
local install_path="${GOPATH%%:*}/src/${package%%/...}"
45-
[[ -e "$install_path/.git/index.lock" ||
46-
-e "$install_path/.hg/store/lock" ||
47-
-e "$install_path/.bzr/checkout/lock" ]] && wait
48-
4949
echo ">> Getting package "$package""
50-
go get -u -d "$package"
50+
51+
# Retries in case of possible race conditions when installing a package
52+
# dependency
53+
for ((i=0; i<5; i++)); do
54+
out=$(go get -u -d "$package" 2>&1 >/dev/null) && break
55+
done
56+
[[ $? != 0 ]] && echo "-- Failed to get "$package", error: " && echo "$out" && exit 1
5157

5258
echo ">> Setting $package to version $version"
5359
cd $install_path
54-
[ -d .hg ] && hg update -q "$version"
60+
is_in_use $install_path && wait
61+
62+
[ -d .hg ] && hg update -q "$version"
5563
[ -d .git ] && git checkout -q "$version"
5664
[ -d .bzr ] && bzr revert -q -r "$version"
5765
[ -d .svn ] && svn update -r "$version"

0 commit comments

Comments
 (0)