Added --dry-run to unlink
Closes Homebrew/homebrew#43561. Signed-off-by: Xu Cheng <xucheng@me.com>
This commit is contained in:
parent
8830e401a9
commit
eff3d21350
@ -1,12 +1,23 @@
|
||||
require "ostruct"
|
||||
|
||||
module Homebrew
|
||||
def unlink
|
||||
raise KegUnspecifiedError if ARGV.named.empty?
|
||||
|
||||
mode = OpenStruct.new
|
||||
mode.dry_run = true if ARGV.dry_run?
|
||||
|
||||
ARGV.kegs.each do |keg|
|
||||
if mode.dry_run
|
||||
puts "Would remove:"
|
||||
keg.unlink(mode)
|
||||
next
|
||||
end
|
||||
|
||||
keg.lock do
|
||||
print "Unlinking #{keg}... "
|
||||
puts if ARGV.verbose?
|
||||
puts "#{keg.unlink} symlinks removed"
|
||||
puts "#{keg.unlink(mode)} symlinks removed"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -186,7 +186,7 @@ class Keg
|
||||
remove_oldname_opt_record
|
||||
end
|
||||
|
||||
def unlink
|
||||
def unlink(mode = OpenStruct.new)
|
||||
ObserverPathnameExtension.reset_counts!
|
||||
|
||||
dirs = []
|
||||
@ -201,6 +201,11 @@ class Keg
|
||||
|
||||
# check whether the file to be unlinked is from the current keg first
|
||||
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.unlink
|
||||
Find.prune if src.directory?
|
||||
@ -208,9 +213,10 @@ class Keg
|
||||
end
|
||||
end
|
||||
|
||||
unless mode.dry_run
|
||||
remove_linked_keg_record if linked?
|
||||
|
||||
dirs.reverse_each(&:rmdir_if_possible)
|
||||
end
|
||||
|
||||
ObserverPathnameExtension.total
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user