From eb5d90c1df4ffcb6189e3bf96a5d75940ca37e38 Mon Sep 17 00:00:00 2001 From: Martin Afanasjew Date: Tue, 20 Oct 2015 07:16:18 +0200 Subject: unlinkapps: avoid deleting too many symlinks Use `start_with?` to make sure the symlink actually points into one of the Homebrew directories (depending on given arguments). Previously, only a substring match was used, which would also remove a symlink to a hypothetical `/opt/unrelated/usr/local/opt/Unrelated.app`. Even if unlikely to occur, altering stuff unrelated to Homebrew is bad. Furthermore, make sure to always use a trailing slash with directories. Otherwise, e.g., `brew unlinkapps qt` will unlink .app bundles of both `qt` and `qt5` if both are installed and `brew linkapps qt qt5` was issued before. (Please ignore that `qt` and `qt5` offer a conflicting set of .app bundles. This will have to be addressed elsewhere.) Closes Homebrew/homebrew#45174. Signed-off-by: Mike McQuaid --- Library/Homebrew/cmd/unlinkapps.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Library') diff --git a/Library/Homebrew/cmd/unlinkapps.rb b/Library/Homebrew/cmd/unlinkapps.rb index 2674b2854..86db7a932 100644 --- a/Library/Homebrew/cmd/unlinkapps.rb +++ b/Library/Homebrew/cmd/unlinkapps.rb @@ -25,9 +25,9 @@ module Homebrew def should_unlink?(file) if ARGV.named.empty? - file.match(HOMEBREW_CELLAR) || file.match("#{HOMEBREW_PREFIX}/opt") + file.start_with?("#{HOMEBREW_CELLAR}/", "#{HOMEBREW_PREFIX}/opt/") else - ARGV.kegs.any? { |keg| file.match(keg.to_s) || file.match(keg.opt_record.to_s) } + ARGV.kegs.any? { |keg| file.start_with?("#{keg}/", "#{keg.opt_record}/") } end end end -- cgit v1.2.3