Skip to content

Commit 7a19f71

Browse files
author
PoTe
committed
Refactors set_dependencies
Doing both `go get` and checkout in the same loop made gpm prone to race conditions - happening when we tried to set versions for packages at the same time they were being installed. Having this happening in two different loops makes the approach more tidy and less prone to error.
1 parent f2daeaa commit 7a19f71

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

bin/gpm

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,22 @@ set_dependencies() {
4949
local install_path="${GOPATH%%:*}/src/${pkg_path%%/...}"
5050
echo ">> Getting package "$package""
5151

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

57+
while read package version; do
58+
(
59+
local pkg_path=$(echo "$package" | awk -F/ '{print $1"/"$2"/"$3}')
60+
local install_path="${GOPATH%%:*}/src/${pkg_path%%/...}"
5961
echo ">> Setting $package to version $version"
6062
cd $install_path
6163
is_in_use $install_path && wait
6264

63-
[ -d .hg ] && hg update -q "$version"
64-
[ -d .git ] && git checkout -q "$version"
6565
[ -d .bzr ] && bzr revert -q -r "$version"
66+
[ -d .git ] && git checkout -q "$version"
67+
[ -d .hg ] && hg update -q "$version"
6668
[ -d .svn ] && svn update -r "$version"
6769
) &
6870
done < <(echo "$deps")

test/installs_correct_versions_test.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ assert "go run go_code.go" "v6.2"
1313
version="a6a0a737c00caf4d4c2bb589941ace0d688168bb"
1414
echo "github.com/garyburd/redigo/redis $version" > Godeps
1515
assert_raises "$GPM"
16-
rm Godeps
17-
cd $GOPATH/src/github.com/garyburd/redigo
16+
cd "${GOPATH%%:*}/src/github.com/garyburd/redigo"
1817
assert "git rev-parse HEAD" "$version"
1918

19+
## Cleanup
20+
rm Godeps
21+
2022
assert_end examples

0 commit comments

Comments
 (0)