Merge pull request #2624 from mistydemeo/use_python_flock
Use Python's flock instead of Ruby's
This commit is contained in:
commit
fb33acbbe4
@ -38,14 +38,19 @@ _create_lock() {
|
|||||||
local lock_fd="$1"
|
local lock_fd="$1"
|
||||||
local name="$2"
|
local name="$2"
|
||||||
local ruby="/usr/bin/ruby"
|
local ruby="/usr/bin/ruby"
|
||||||
|
local python="/usr/bin/python"
|
||||||
[[ -x "$ruby" ]] || ruby="$(which ruby 2>/dev/null)"
|
[[ -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
|
then
|
||||||
"$ruby" -e "File.new($lock_fd).flock(File::LOCK_EX | File::LOCK_NB) || exit(1)"
|
"$ruby" -e "File.new($lock_fd).flock(File::LOCK_EX | File::LOCK_NB) || exit(1)"
|
||||||
elif [[ -n "$(which flock)" ]]
|
elif [[ -x "$(which flock)" ]]
|
||||||
then
|
then
|
||||||
flock -n "$lock_fd"
|
flock -n "$lock_fd"
|
||||||
|
elif [[ -x "$python" ]]
|
||||||
|
then
|
||||||
|
"$python" -c "import fcntl; fcntl.flock($lock_fd, fcntl.LOCK_EX | fcntl.LOCK_NB)"
|
||||||
else
|
else
|
||||||
onoe "Cannot create $name lock, please avoid running Homebrew in parallel."
|
onoe "Cannot create $name lock, please avoid running Homebrew in parallel."
|
||||||
fi
|
fi
|
||||||
|
Loading…
x
Reference in New Issue
Block a user