linkapps: deal only with kegs, not formulae

Fixes Homebrew/homebrew#19873.
This commit is contained in:
Jack Nagel 2013-05-16 14:36:50 -05:00
parent 2d8496129c
commit e8997c8a5a

View File

@ -1,5 +1,5 @@
# Links any Applications (.app) found in installed prefixes to ~/Applications # Links any Applications (.app) found in installed prefixes to ~/Applications
require "formula" require 'keg'
TARGET_DIR = ARGV.include?("--system") ? "/Applications" : File.expand_path("~/Applications") TARGET_DIR = ARGV.include?("--system") ? "/Applications" : File.expand_path("~/Applications")
@ -9,24 +9,24 @@ unless File.exist? TARGET_DIR
exit 1 exit 1
end end
HOMEBREW_CELLAR.subdirs.each do |keg| HOMEBREW_CELLAR.subdirs.each do |rack|
next unless keg.subdirs kegs = rack.subdirs.map { |d| Keg.new(d) }
name = keg.basename.to_s next if kegs.empty?
if ((f = Formula.factory(name)).installed? rescue false) keg = kegs.detect(&:linked?) || kegs.max_by(&:version)
Dir["#{f.installed_prefix}/*.app", "#{f.installed_prefix}/bin/*.app", "#{f.installed_prefix}/libexec/*.app"].each do |p|
puts "Linking #{p}" Dir["#{keg}/*.app", "#{keg}/bin/*.app", "#{keg}/libexec/*.app"].each do |app|
appname = File.basename(p) puts "Linking #{app}"
target = TARGET_DIR+"/"+appname app_name = File.basename(app)
if File.exist? target target = "#{TARGET_DIR}/#{app_name}"
if File.symlink? target
system "rm", target if File.exist?(target) && File.symlink?(target)
else system "rm", target
onoe "#{target} already exists, skipping." elsif File.exist?(target)
end onoe "#{target} already exists, skipping."
end next
system "ln", "-s", p, TARGET_DIR
end end
system "ln", "-s", app, TARGET_DIR
end end
end end