Added --dry-run to unlink

Closes Homebrew/homebrew#43561.

Signed-off-by: Xu Cheng <xucheng@me.com>
This commit is contained in:
Ethan Piekarski 2015-09-06 15:25:36 +08:00 committed by Xu Cheng
parent 8830e401a9
commit eff3d21350
2 changed files with 22 additions and 5 deletions

View File

@ -1,12 +1,23 @@
require "ostruct"
module Homebrew module Homebrew
def unlink def unlink
raise KegUnspecifiedError if ARGV.named.empty? raise KegUnspecifiedError if ARGV.named.empty?
mode = OpenStruct.new
mode.dry_run = true if ARGV.dry_run?
ARGV.kegs.each do |keg| ARGV.kegs.each do |keg|
if mode.dry_run
puts "Would remove:"
keg.unlink(mode)
next
end
keg.lock do keg.lock do
print "Unlinking #{keg}... " print "Unlinking #{keg}... "
puts if ARGV.verbose? puts if ARGV.verbose?
puts "#{keg.unlink} symlinks removed" puts "#{keg.unlink(mode)} symlinks removed"
end end
end end
end end

View File

@ -186,7 +186,7 @@ class Keg
remove_oldname_opt_record remove_oldname_opt_record
end end
def unlink def unlink(mode = OpenStruct.new)
ObserverPathnameExtension.reset_counts! ObserverPathnameExtension.reset_counts!
dirs = [] dirs = []
@ -201,6 +201,11 @@ class Keg
# check whether the file to be unlinked is from the current keg first # check whether the file to be unlinked is from the current keg first
if dst.symlink? && src == dst.resolved_path if dst.symlink? && src == dst.resolved_path
if mode.dry_run
puts dst
next
end
dst.uninstall_info if dst.to_s =~ INFOFILE_RX dst.uninstall_info if dst.to_s =~ INFOFILE_RX
dst.unlink dst.unlink
Find.prune if src.directory? Find.prune if src.directory?
@ -208,9 +213,10 @@ class Keg
end end
end end
unless mode.dry_run
remove_linked_keg_record if linked? remove_linked_keg_record if linked?
dirs.reverse_each(&:rmdir_if_possible) dirs.reverse_each(&:rmdir_if_possible)
end
ObserverPathnameExtension.total ObserverPathnameExtension.total
end end