Skip to content

Commit 3f86977

Browse files
committed
Prevents race conditions between dependencies (Fixes #35)
* Refactors the scm lock * Restries `go get` until it's not locked anymore
1 parent 7d5360a commit 3f86977

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

bin/gpm

Lines changed: 8 additions & 5 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,15 @@ 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
49+
is_in_use $install_path && wait
4850

4951
echo ">> Getting package "$package""
50-
go get -u -d "$package"
52+
while true; do go get -u -d "$package" 2> /dev/null && break; done
5153

5254
echo ">> Setting $package to version $version"
5355
cd $install_path
54-
[ -d .hg ] && hg update -q "$version"
56+
57+
[ -d .hg ] && hg update -q "$version"
5558
[ -d .git ] && git checkout -q "$version"
5659
[ -d .bzr ] && bzr revert -q -r "$version"
5760
[ -d .svn ] && svn update -r "$version"

0 commit comments

Comments
 (0)