Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

Commit

Permalink
Fix issues with writable? detection in brew doctor
Browse files Browse the repository at this point in the history
Closes #13689.

Signed-off-by: Max Howell <mxcl@me.com>

There are subtle distinctions between writable? and writable_real? we don't
understand precisely why we need this, but it fixes the bugs :/
  • Loading branch information
Brandon Black authored and mxcl committed Aug 7, 2012
1 parent 0bd72cb commit 8aa4f9d
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Library/Contributions/cmds/brew-unpack.rb
Expand Up @@ -73,7 +73,7 @@ def unpack
unpack_dir.mkpath unless unpack_dir.exist?
end

raise "Cannot write to #{unpack_dir}" unless unpack_dir.writable?
raise "Cannot write to #{unpack_dir}" unless unpack_dir.writable_real?

formulae.each do |f|
# Create a nice name for the stage folder.
Expand Down
2 changes: 1 addition & 1 deletion Library/Contributions/install_homebrew.rb
Expand Up @@ -84,7 +84,7 @@ def macos_version
share/man/man5 share/man/man6 share/man/man7 share/man/man8
share/info share/doc share/aclocal ).
map{ |d| "/usr/local/#{d}" }.
select{ |d| File.directory? d and not File.writable? d }
select{ |d| File.directory? d and not File.writable_real? d }
chgrps = chmods.reject{ |d| File.stat(d).grpowned? }

unless chmods.empty?
Expand Down
6 changes: 3 additions & 3 deletions Library/Homebrew/cmd/doctor.rb
Expand Up @@ -279,7 +279,7 @@ def __check_subdir_access base

target.find do |d|
next unless d.directory?
cant_read << d unless d.writable?
cant_read << d unless d.writable_real?
end

cant_read.sort!
Expand All @@ -300,7 +300,7 @@ def __check_subdir_access base
def check_access_usr_local
return unless HOMEBREW_PREFIX.to_s == '/usr/local'

unless Pathname('/usr/local').writable? then <<-EOS.undent
unless Pathname('/usr/local').writable_real? then <<-EOS.undent
The /usr/local directory is not writable.
Even if this directory was writable when you installed Homebrew, other
software may change permissions on this directory. Some versions of the
Expand All @@ -322,7 +322,7 @@ def check_access_share_man

def __check_folder_access base, msg
folder = HOMEBREW_PREFIX+base
if folder.exist? and not folder.writable?
if folder.exist? and not folder.writable_real?
<<-EOS.undent
#{folder} isn't writable.
This can happen if you "sudo make install" software that isn't managed
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/cmd/install.rb
Expand Up @@ -33,8 +33,8 @@ def check_ppc
end

def check_writable_install_location
raise "Cannot write to #{HOMEBREW_CELLAR}" if HOMEBREW_CELLAR.exist? and not HOMEBREW_CELLAR.writable?
raise "Cannot write to #{HOMEBREW_PREFIX}" unless HOMEBREW_PREFIX.writable? or HOMEBREW_PREFIX.to_s == '/usr/local'
raise "Cannot write to #{HOMEBREW_CELLAR}" if HOMEBREW_CELLAR.exist? and not HOMEBREW_CELLAR.writable_real?
raise "Cannot write to #{HOMEBREW_PREFIX}" unless HOMEBREW_PREFIX.writable_real? or HOMEBREW_PREFIX.to_s == '/usr/local'
end

def check_xcode
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/extend/pathname.rb
Expand Up @@ -353,7 +353,7 @@ def make_relative_symlink src
To list all files that would be deleted:
brew link -n formula_name
EOS
elsif !dirname.writable?
elsif !dirname.writable_real?
raise <<-EOS.undent
Could not symlink file: #{src.expand_path}
#{dirname} is not writable. You should change its permissions.
Expand All @@ -375,7 +375,7 @@ def / that
def ensure_writable
saved_perms = nil
unless writable?
unless writable_real?
saved_perms = stat.mode
chmod 0644
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/global.rb
Expand Up @@ -16,7 +16,7 @@ def cache
# we do this for historic reasons, however the cache *should* be the same
# directory whichever user is used and whatever instance of brew is executed
home_cache = Pathname.new("~/Library/Caches/Homebrew").expand_path
if home_cache.directory? and home_cache.writable?
if home_cache.directory? and home_cache.writable_real?
home_cache
else
root_cache = Pathname.new("/Library/Caches/Homebrew")
Expand Down

0 comments on commit 8aa4f9d

Please sign in to comment.