Merge pull request #1486 from MikeMcQuaid/lock_dir_permissions

Check the lock directory is writable.
This commit is contained in:
Mike McQuaid 2016-11-12 10:38:08 +00:00 committed by GitHub
commit f184eba20b
2 changed files with 26 additions and 3 deletions

View File

@ -348,6 +348,20 @@ module Homebrew
EOS EOS
end 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 def check_access_logs
return unless HOMEBREW_LOGS.exist? return unless HOMEBREW_LOGS.exist?
return if HOMEBREW_LOGS.writable_real? return if HOMEBREW_LOGS.writable_real?

View File

@ -6,6 +6,14 @@ lock() {
local lock_dir="$HOMEBREW_PREFIX/var/homebrew/locks" local lock_dir="$HOMEBREW_PREFIX/var/homebrew/locks"
local lock_file="$lock_dir/$name" local lock_file="$lock_dir/$name"
[[ -d "$lock_dir" ]] || mkdir -p "$lock_dir" [[ -d "$lock_dir" ]] || mkdir -p "$lock_dir"
if ! [[ -w "$lock_dir" ]]
then
odie <<EOS
Can't create $name lock in $lock_dir!
Fix permissions by running:
sudo chown -R \$(whoami) $HOMEBREW_PREFIX/var/homebrew
EOS
fi
# 200 is the file descriptor used in the lock. # 200 is the file descriptor used in the lock.
# This FD should be used exclusively for lock purpose. # This FD should be used exclusively for lock purpose.
# Any value except 0(stdin), 1(stdout) and 2(stderr) can do the job. # Any value except 0(stdin), 1(stdout) and 2(stderr) can do the job.
@ -17,10 +25,10 @@ lock() {
exec 200>&- exec 200>&-
# open the lock file to FD, so the shell process can hold the lock. # open the lock file to FD, so the shell process can hold the lock.
exec 200>"$lock_file" exec 200>"$lock_file"
if ! _create_lock 200 if ! _create_lock 200 "$name"
then then
odie <<EOS odie <<EOS
Another active Homebrew process is already in progress. Another active Homebrew $name process is already in progress.
Please wait for it to finish or terminate it to continue. Please wait for it to finish or terminate it to continue.
EOS EOS
fi fi
@ -28,6 +36,7 @@ EOS
_create_lock() { _create_lock() {
local lock_fd="$1" local lock_fd="$1"
local name="$2"
local ruby="/usr/bin/ruby" local ruby="/usr/bin/ruby"
[[ -x "$ruby" ]] || ruby="$(which ruby 2>/dev/null)" [[ -x "$ruby" ]] || ruby="$(which ruby 2>/dev/null)"
@ -38,6 +47,6 @@ _create_lock() {
then then
flock -n "$lock_fd" flock -n "$lock_fd"
else else
onoe "Cannot create lock, please avoid running brew in parallel." onoe "Cannot create $name lock, please avoid running Homebrew in parallel."
fi fi
} }