aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMisty De Meo2017-05-11 12:06:55 -0700
committerMisty De Meo2017-05-23 17:50:22 -0700
commit129ee966f8a9d1287d3407f81b214ba744b7d4c5 (patch)
tree334376ba1909230e7a7d0e63baa6c82bed5ed416 /Library
parentfdd9972aa7c6267fad8c5648a203d0e24a6fdf0a (diff)
downloadbrew-129ee966f8a9d1287d3407f81b214ba744b7d4c5.tar.bz2
Optionally use Python's flock instead of Ruby's
Ruby first gained flock in 1.8.7, which is a problem since we're using this lock utility in `vendor-install` in order to install a newer Ruby. Fortunately, Python 2.3(!) has flock support.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/utils/lock.sh7
1 files changed, 6 insertions, 1 deletions
diff --git a/Library/Homebrew/utils/lock.sh b/Library/Homebrew/utils/lock.sh
index 7f0638c1a..04d8fd1d5 100644
--- a/Library/Homebrew/utils/lock.sh
+++ b/Library/Homebrew/utils/lock.sh
@@ -38,14 +38,19 @@ _create_lock() {
local lock_fd="$1"
local name="$2"
local ruby="/usr/bin/ruby"
+ local python="/usr/bin/python"
[[ -x "$ruby" ]] || ruby="$(which ruby 2>/dev/null)"
+ [[ -x "$python" ]] || python="$(which python 2>/dev/null)"
- if [[ -n "$ruby" ]]
+ if [[ -n "$ruby" && $("$ruby" -e "puts RUBY_VERSION >= '1.8.7' ? 0 : 1") = 0 ]]
then
"$ruby" -e "File.new($lock_fd).flock(File::LOCK_EX | File::LOCK_NB) || exit(1)"
elif [[ -n "$(which flock)" ]]
then
flock -n "$lock_fd"
+ elif [[ -n "$python" ]]
+ then
+ "$python" -c "import fcntl; fcntl.flock($lock_fd, fcntl.LOCK_EX | fcntl.LOCK_NB)"
else
onoe "Cannot create $name lock, please avoid running Homebrew in parallel."
fi