2015-12-08 07:59:14 +01:00
|
|
|
require "cmd/linkapps"
|
2013-09-21 17:11:25 +02:00
|
|
|
|
2014-06-18 22:41:47 -05:00
|
|
|
module Homebrew
|
2013-09-21 17:11:25 +02:00
|
|
|
def unlinkapps
|
2015-12-08 07:59:14 +01:00
|
|
|
target_dir = linkapps_target(:local => ARGV.include?("--local"))
|
2013-09-21 17:11:25 +02:00
|
|
|
|
2015-12-08 07:59:14 +01:00
|
|
|
unlinkapps_from_dir(target_dir)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2013-09-21 17:11:25 +02:00
|
|
|
|
2015-12-08 07:59:14 +01:00
|
|
|
def unlinkapps_from_dir(target_dir)
|
|
|
|
return unless target_dir.directory?
|
|
|
|
|
|
|
|
apps = Pathname.glob("#{target_dir}/*.app").select do |app|
|
|
|
|
unlinkapps_unlink?(app)
|
2013-09-21 17:11:25 +02:00
|
|
|
end
|
|
|
|
|
2015-12-08 07:59:14 +01:00
|
|
|
ObserverPathnameExtension.reset_counts!
|
|
|
|
|
|
|
|
apps.each do |app|
|
|
|
|
app.extend(ObserverPathnameExtension)
|
|
|
|
puts "Unlinking: #{app}"
|
|
|
|
app.unlink
|
2013-09-21 17:11:25 +02:00
|
|
|
end
|
|
|
|
|
2015-12-08 07:59:14 +01:00
|
|
|
if ObserverPathnameExtension.total.zero?
|
|
|
|
puts "No apps unlinked from #{target_dir}" if ARGV.verbose?
|
|
|
|
else
|
|
|
|
n = ObserverPathnameExtension.total
|
|
|
|
puts "Unlinked #{n} app#{plural(n)} from #{target_dir}"
|
|
|
|
end
|
2013-09-21 17:11:25 +02:00
|
|
|
end
|
2014-12-18 15:13:04 +08:00
|
|
|
|
2015-12-08 07:59:14 +01:00
|
|
|
UNLINKAPPS_PREFIXES = %W[
|
|
|
|
#{HOMEBREW_CELLAR}/
|
|
|
|
#{HOMEBREW_PREFIX}/opt/
|
|
|
|
].freeze
|
|
|
|
|
|
|
|
def unlinkapps_unlink?(target_app)
|
|
|
|
# Skip non-symlinks and symlinks that don't point into the Homebrew prefix.
|
|
|
|
app = "#{target_app.readlink}" if target_app.symlink?
|
|
|
|
return false unless app && app.start_with?(*UNLINKAPPS_PREFIXES)
|
2014-12-18 15:13:04 +08:00
|
|
|
|
|
|
|
if ARGV.named.empty?
|
2015-12-08 07:59:14 +01:00
|
|
|
true
|
2014-12-18 15:13:04 +08:00
|
|
|
else
|
2015-12-08 07:59:14 +01:00
|
|
|
ARGV.kegs.any? { |keg| app.start_with?("#{keg}/", "#{keg.opt_record}/") }
|
2014-12-18 15:13:04 +08:00
|
|
|
end
|
|
|
|
end
|
2013-09-21 17:11:25 +02:00
|
|
|
end
|