diagnostic: remove duplicate checks.

This commit is contained in:
Mike McQuaid 2016-09-09 13:08:02 +01:00
parent b5a6b4e8e1
commit 30fd4f3fe5
2 changed files with 13 additions and 94 deletions

View File

@ -283,35 +283,16 @@ module Homebrew
EOS EOS
end end
def __check_subdir_access(base) def check_tmpdir_sticky_bit
target = HOMEBREW_PREFIX+base world_writable = HOMEBREW_TEMP.stat.mode & 0777 == 0777
return unless target.exist? return if !world_writable || HOMEBREW_TEMP.sticky?
cant_read = [] <<-EOS.undent
target.find do |d| #{HOMEBREW_TEMP} is world-writable but does not have the sticky bit set.
next unless d.directory? Please execute `sudo chmod +t #{HOMEBREW_TEMP}` in your Terminal.
cant_read << d unless d.writable_real?
end
return if cant_read.empty?
inject_file_list cant_read.sort, <<-EOS.undent
Some directories in #{target} aren't writable.
This can happen if you "sudo make install" software that isn't managed
by Homebrew. If a brew tries to add locale information to one of these
directories, then the install will fail during the link step.
You should `sudo chown -R $(whoami)` them:
EOS EOS
end end
def check_access_share_locale
__check_subdir_access "share/locale"
end
def check_access_share_man
__check_subdir_access "share/man"
end
def check_access_homebrew_repository def check_access_homebrew_repository
return if HOMEBREW_REPOSITORY.writable_real? return if HOMEBREW_REPOSITORY.writable_real?
@ -324,22 +305,11 @@ module Homebrew
EOS EOS
end end
def check_access_homebrew_cellar def check_access_prefix_directories
return if HOMEBREW_CELLAR.writable_real?
<<-EOS.undent
#{HOMEBREW_CELLAR} is not writable.
You should change the ownership and permissions of #{HOMEBREW_CELLAR}
back to your user account.
sudo chown -R $(whoami) #{HOMEBREW_CELLAR}
EOS
end
def check_access_top_level_directories
not_writable_dirs = [] not_writable_dirs = []
(Keg::TOP_LEVEL_DIRECTORIES + ["opt"]).each do |dir| extra_dirs = ["lib/pkgconfig", "share/locale", "share/man", "opt"]
(Keg::TOP_LEVEL_DIRECTORIES + extra_dirs).each do |dir|
path = HOMEBREW_PREFIX/dir path = HOMEBREW_PREFIX/dir
next unless path.exist? next unless path.exist?
next if path.writable_real? next if path.writable_real?
@ -352,42 +322,16 @@ module Homebrew
The following directories are not writable: The following directories are not writable:
#{not_writable_dirs.join("\n")} #{not_writable_dirs.join("\n")}
This can happen if you "sudo make install" software that isn't managed
by Homebrew. If a formula tries to write a file to this directory, the
install will fail during the link step.
You should change the ownership and permissions of these directories. You should change the ownership and permissions of these directories.
back to your user account. back to your user account.
sudo chown -R $(whoami) #{not_writable_dirs.join(" ")} sudo chown -R $(whoami) #{not_writable_dirs.join(" ")}
EOS EOS
end end
def check_tmpdir_sticky_bit
world_writable = HOMEBREW_TEMP.stat.mode & 0777 == 0777
return if !world_writable || HOMEBREW_TEMP.sticky?
<<-EOS.undent
#{HOMEBREW_TEMP} is world-writable but does not have the sticky bit set.
Please execute `sudo chmod +t #{HOMEBREW_TEMP}` in your Terminal.
EOS
end
(Keg::TOP_LEVEL_DIRECTORIES + ["lib/pkgconfig"]).each do |d|
define_method("check_access_#{d.sub("/", "_")}") do
dir = HOMEBREW_PREFIX.join(d)
return unless dir.exist?
return if dir.writable_real?
<<-EOS.undent
#{dir} isn't writable.
This can happen if you "sudo make install" software that isn't managed
by Homebrew. If a formula tries to write a file to this directory, the
install will fail during the link step.
You should change the ownership and permissions of #{dir} back to
your user account.
sudo chown -R $(whoami) #{dir}
EOS
end
end
def check_access_site_packages def check_access_site_packages
return unless Language::Python.homebrew_site_packages.exist? return unless Language::Python.homebrew_site_packages.exist?
return if Language::Python.homebrew_site_packages.writable_real? return if Language::Python.homebrew_site_packages.writable_real?
@ -446,20 +390,6 @@ module Homebrew
EOS EOS
end end
def check_access_prefix_opt
opt = HOMEBREW_PREFIX.join("opt")
return unless opt.exist?
return if opt.writable_real?
<<-EOS.undent
#{opt} isn't writable.
You should change the ownership and permissions of #{opt}
back to your user account.
sudo chown -R $(whoami) #{opt}
EOS
end
def check_homebrew_prefix def check_homebrew_prefix
return if HOMEBREW_PREFIX.to_s == "/usr/local" return if HOMEBREW_PREFIX.to_s == "/usr/local"

View File

@ -83,17 +83,6 @@ class DiagnosticChecksTest < Homebrew::TestCase
HOMEBREW_CELLAR.chmod mod HOMEBREW_CELLAR.chmod mod
end end
def test_check_access_prefix_opt
opt = HOMEBREW_PREFIX.join("opt")
opt.mkpath
opt.chmod 0555
assert_match "#{opt} isn't writable.",
@checks.check_access_prefix_opt
ensure
opt.unlink
end
def test_check_homebrew_prefix def test_check_homebrew_prefix
# the integration tests are run in a special prefix # the integration tests are run in a special prefix
assert_match "Your Homebrew is not installed to /usr/local", assert_match "Your Homebrew is not installed to /usr/local",