diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index 216b298fc9..0b32f64c7c 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -348,6 +348,20 @@ module Homebrew EOS end + def check_access_lock_dir + return unless HOMEBREW_LOCK_DIR.exist? + return if HOMEBREW_LOCK_DIR.writable_real? + + <<-EOS.undent + #{HOMEBREW_LOCK_DIR} isn't writable. + Homebrew writes lock files to this location. + + You should change the ownership and permissions of #{HOMEBREW_LOCK_DIR} + back to your user account. + sudo chown -R $(whoami) #{HOMEBREW_LOCK_DIR} + EOS + end + def check_access_logs return unless HOMEBREW_LOGS.exist? return if HOMEBREW_LOGS.writable_real? diff --git a/Library/Homebrew/utils/lock.sh b/Library/Homebrew/utils/lock.sh index cc041fa742..7f0638c1ac 100644 --- a/Library/Homebrew/utils/lock.sh +++ b/Library/Homebrew/utils/lock.sh @@ -6,6 +6,14 @@ lock() { 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 + if ! _create_lock 200 "$name" then odie <