Merge pull request #18516 from Homebrew/lockf-macos-15

utils/lock: use new lockf where available
This commit is contained in:
Bo Anderson 2024-10-25 03:09:12 +01:00 committed by GitHub
commit ddfe04a601
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -56,12 +56,16 @@ _create_lock() {
local utils_lock_sh="${HOMEBREW_LIBRARY}/Homebrew/utils/lock_sh" local utils_lock_sh="${HOMEBREW_LIBRARY}/Homebrew/utils/lock_sh"
local oldest_ruby_with_flock="1.8.7" local oldest_ruby_with_flock="1.8.7"
if [[ -x "${ruby}" ]] && "${ruby}" "${utils_lock_sh}/ruby_check_version.rb" "${oldest_ruby_with_flock}"
if [[ -x "$(type -P lockf)" ]]
then then
"${ruby}" "${utils_lock_sh}/ruby_lock_file_descriptor.rb" "${lock_file_descriptor}" lockf -t 0 "${lock_file_descriptor}"
elif [[ -x "$(type -P flock)" ]] elif [[ -x "$(type -P flock)" ]]
then then
flock -n "${lock_file_descriptor}" flock -n "${lock_file_descriptor}"
elif [[ -x "${ruby}" ]] && "${ruby}" "${utils_lock_sh}/ruby_check_version.rb" "${oldest_ruby_with_flock}"
then
"${ruby}" "${utils_lock_sh}/ruby_lock_file_descriptor.rb" "${lock_file_descriptor}"
elif [[ -x "${python}" ]] elif [[ -x "${python}" ]]
then then
"${python}" -c "import fcntl; fcntl.flock(${lock_file_descriptor}, fcntl.LOCK_EX | fcntl.LOCK_NB)" "${python}" -c "import fcntl; fcntl.flock(${lock_file_descriptor}, fcntl.LOCK_EX | fcntl.LOCK_NB)"