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

Commit

Permalink
Record which keg is linked
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mxcl committed Aug 24, 2011
1 parent 179bad1 commit 3da76d0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -7,3 +7,4 @@
!/bin/brew
!/share/man/man1/brew.1
.DS_Store
/Library/LinkedKegs
6 changes: 6 additions & 0 deletions Library/Homebrew/cmd/install.rb
Expand Up @@ -9,6 +9,12 @@ def install
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.
Expand Down
13 changes: 13 additions & 0 deletions Library/Homebrew/keg.rb
Expand Up @@ -33,10 +33,21 @@ def unlink
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

Expand Down Expand Up @@ -68,6 +79,8 @@ def link
end
end

(HOMEBREW_REPOSITORY/"Library/LinkedKegs"/fname).make_relative_symlink(self)

return $n+$d
end

Expand Down

0 comments on commit 3da76d0

Please sign in to comment.