From 129ee966f8a9d1287d3407f81b214ba744b7d4c5 Mon Sep 17 00:00:00 2001 From: Misty De Meo Date: Thu, 11 May 2017 12:06:55 -0700 Subject: [PATCH 1/3] 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. --- Library/Homebrew/utils/lock.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/utils/lock.sh b/Library/Homebrew/utils/lock.sh index 7f0638c1ac..04d8fd1d59 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 From 94ed3e358399db37ff88c8a53c6c8cbf7a44e51e Mon Sep 17 00:00:00 2001 From: Misty De Meo Date: Tue, 23 May 2017 18:36:06 -0700 Subject: [PATCH 2/3] lock: check tools are executable --- Library/Homebrew/utils/lock.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/utils/lock.sh b/Library/Homebrew/utils/lock.sh index 04d8fd1d59..b3c23c3ef3 100644 --- a/Library/Homebrew/utils/lock.sh +++ b/Library/Homebrew/utils/lock.sh @@ -42,13 +42,13 @@ _create_lock() { [[ -x "$ruby" ]] || ruby="$(which ruby 2>/dev/null)" [[ -x "$python" ]] || python="$(which python 2>/dev/null)" - if [[ -n "$ruby" && $("$ruby" -e "puts RUBY_VERSION >= '1.8.7' ? 0 : 1") = 0 ]] + if [[ -x "$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)" ]] + elif [[ -x "$(which flock)" ]] then flock -n "$lock_fd" - elif [[ -n "$python" ]] + elif [[ -x "$python" ]] then "$python" -c "import fcntl; fcntl.flock($lock_fd, fcntl.LOCK_EX | fcntl.LOCK_NB)" else From 67dc3323ed1368ffc6a49899c8b98732dc2eb181 Mon Sep 17 00:00:00 2001 From: Misty De Meo Date: Wed, 24 May 2017 09:12:21 -0700 Subject: [PATCH 3/3] lock: simplify ruby conditional --- Library/Homebrew/utils/lock.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/utils/lock.sh b/Library/Homebrew/utils/lock.sh index b3c23c3ef3..7f2bb8b73f 100644 --- a/Library/Homebrew/utils/lock.sh +++ b/Library/Homebrew/utils/lock.sh @@ -42,7 +42,7 @@ _create_lock() { [[ -x "$ruby" ]] || ruby="$(which ruby 2>/dev/null)" [[ -x "$python" ]] || python="$(which python 2>/dev/null)" - if [[ -x "$ruby" && $("$ruby" -e "puts RUBY_VERSION >= '1.8.7' ? 0 : 1") = 0 ]] + 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 [[ -x "$(which flock)" ]]