aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMisty De Meo2017-05-25 11:48:15 -0700
committerGitHub2017-05-25 11:48:15 -0700
commitfb33acbbe47162adf90e92cbb6b244f26a5a346e (patch)
tree69cec19ca322e7df07f6bf33b32a78454b1442ea
parente931fee732d9d8d34eb9d689782bafb3822302f7 (diff)
parent67dc3323ed1368ffc6a49899c8b98732dc2eb181 (diff)
downloadbrew-fb33acbbe47162adf90e92cbb6b244f26a5a346e.tar.bz2
Merge pull request #2624 from mistydemeo/use_python_flock
Use Python's flock instead of Ruby's
-rw-r--r--Library/Homebrew/utils/lock.sh9
1 files changed, 7 insertions, 2 deletions
diff --git a/Library/Homebrew/utils/lock.sh b/Library/Homebrew/utils/lock.sh
index 7f0638c1a..7f2bb8b73 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 [[ -x "$ruby" ]] && "$ruby" -e "exit(RUBY_VERSION >= '1.8.7')"
then
"$ruby" -e "File.new($lock_fd).flock(File::LOCK_EX | File::LOCK_NB) || exit(1)"
- elif [[ -n "$(which flock)" ]]
+ elif [[ -x "$(which flock)" ]]
then
flock -n "$lock_fd"
+ elif [[ -x "$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