diff options
| author | Max Howell | 2011-08-24 11:30:32 +0100 |
|---|---|---|
| committer | Max Howell | 2011-08-24 22:30:44 +0100 |
| commit | 3da76d0f37318c2beafae326bbc029ec4a36047e (patch) | |
| tree | 5376957d75d87d974ebde9a5a353deab7d2bfdab | |
| parent | 179bad1b1d3a79104bd248af42ac8322a267db68 (diff) | |
| download | homebrew-3da76d0f37318c2beafae326bbc029ec4a36047e.tar.bz2 | |
Record which keg is linked
Will be useful for a variety of reasons, but for now, I'm just using it to ensure install won't install again if something is already installed (use brew upgrade instead).
But means that brew switch and that can work properly etc.
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | Library/Homebrew/cmd/install.rb | 6 | ||||
| -rw-r--r-- | Library/Homebrew/keg.rb | 13 |
3 files changed, 20 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore index a2ccbd76c..60119cef7 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ !/bin/brew !/share/man/man1/brew.1 .DS_Store +/Library/LinkedKegs
\ No newline at end of file diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 4b2711994..07942f64e 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -9,6 +9,12 @@ module Homebrew extend self raise "No available formula for #{name}\n#{msg}" if msg end unless ARGV.force? + ARGV.formulae.each do |f| + if File.directory? HOMEBREW_REPOSITORY/"Library/LinkedKegs/#{f.name}" + raise "#{f} already installed\nTry: brew upgrade #{f}" + end + end + if Process.uid.zero? and not File.stat(HOMEBREW_BREW_FILE).uid.zero? # note we only abort if Homebrew is *not* installed as sudo and the user # calls brew as root. The fix is to chown brew to root. diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb index ad0e97653..a0d028d08 100644 --- a/Library/Homebrew/keg.rb +++ b/Library/Homebrew/keg.rb @@ -33,10 +33,21 @@ class Keg < Pathname n+=1 Find.prune if src.directory? end + linked_keg_record.unlink if linked_keg_record.exist? n end + def fname + parent.basename.to_s + end + + def linked_keg_record + @linked_keg_record ||= HOMEBREW_REPOSITORY/"Library/LinkedKegs"/fname + end + def link + raise "Cannot link #{fname}\nAnother version is already linked: #{linked_keg_record.realpath}" if linked_keg_record.directory? + $n=0 $d=0 @@ -68,6 +79,8 @@ class Keg < Pathname end end + (HOMEBREW_REPOSITORY/"Library/LinkedKegs"/fname).make_relative_symlink(self) + return $n+$d end |
