From 05260f4565eb51c9364cc1c0b515b152089d703f Mon Sep 17 00:00:00 2001 From: hyuraku <32809703+hyuraku@users.noreply.github.com> Date: Wed, 21 Apr 2021 20:51:50 +0900 Subject: [PATCH] utils/lock.sh: repair style --- Library/Homebrew/utils/lock.sh | 36 ++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/Library/Homebrew/utils/lock.sh b/Library/Homebrew/utils/lock.sh index 060941d78a..010ea5ca14 100644 --- a/Library/Homebrew/utils/lock.sh +++ b/Library/Homebrew/utils/lock.sh @@ -1,17 +1,19 @@ # create a lock using `flock(2)`. A name is required as first argument. # the lock will be automatically unlocked when the shell process quits. # Noted due to the fixed FD, a shell process can only create one lock. +# HOMEBREW_PREFIX is set by extend/ENV/super.rb +# shellcheck disable=SC2154 lock() { local name="$1" - local lock_dir="$HOMEBREW_PREFIX/var/homebrew/locks" - local lock_file="$lock_dir/$name" - [[ -d "$lock_dir" ]] || mkdir -p "$lock_dir" - if ! [[ -w "$lock_dir" ]] + local lock_dir="${HOMEBREW_PREFIX}/var/homebrew/locks" + local lock_file="${lock_dir}/${name}" + [[ -d "${lock_dir}" ]] || mkdir -p "${lock_dir}" + if ! [[ -w "${lock_dir}" ]] then odie <&- # open the lock file to FD, so the shell process can hold the lock. - exec 200>"$lock_file" - if ! _create_lock 200 "$name" + exec 200>"${lock_file}" + if ! _create_lock 200 "${name}" then odie <= '1.8.7')" + 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 "$python" ]] + "${ruby}" -e "File.new(${lock_fd}).flock(File::LOCK_EX | File::LOCK_NB) || exit(1)" + elif [[ -x "${python}" ]] then - "$python" -c "import fcntl; fcntl.flock($lock_fd, fcntl.LOCK_EX | fcntl.LOCK_NB)" + "${python}" -c "import fcntl; fcntl.flock(${lock_fd}, fcntl.LOCK_EX | fcntl.LOCK_NB)" elif [[ -x "$(type -P flock)" ]] then - flock -n "$lock_fd" + flock -n "${lock_fd}" else - onoe "Cannot create $name lock, please avoid running Homebrew in parallel." + onoe "Cannot create ${name} lock, please avoid running Homebrew in parallel." fi }