From dfbc09c12f205734a71fed87f068fec33bf6b85c Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Thu, 9 Jul 2020 14:21:09 +0100 Subject: [PATCH] keg: general cleanup. Some refactoring while doing #7956. --- Library/Homebrew/keg.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb index 7edb23361..321007f5a 100644 --- a/Library/Homebrew/keg.rb +++ b/Library/Homebrew/keg.rb @@ -195,7 +195,7 @@ class Keg def initialize(path) path = path.resolved_path if path.to_s.start_with?("#{HOMEBREW_PREFIX}/opt/") - raise "#{path} is not a valid keg" unless path.parent.parent.realpath == HOMEBREW_CELLAR.realpath + raise "#{path} is not a valid keg" if path.parent.parent.realpath != HOMEBREW_CELLAR.realpath raise "#{path} is not a directory" unless path.directory? @path = path @@ -322,9 +322,9 @@ class Keg dirs = [] - KEG_LINK_DIRECTORIES.map { |d| path/d }.each do |dir| - next unless dir.exist? - + keg_directories = KEG_LINK_DIRECTORIES.map { |d| path/d } + .select(&:exist?) + keg_directories.each do |dir| dir.find do |src| dst = HOMEBREW_PREFIX + src.relative_path_from(path) dst.extend(ObserverPathnameExtension) @@ -332,7 +332,8 @@ class Keg dirs << dst if dst.directory? && !dst.symlink? # check whether the file to be unlinked is from the current keg first - next unless dst.symlink? && src == dst.resolved_path + next unless dst.symlink? + next if src != dst.resolved_path if mode.dry_run puts dst @@ -509,7 +510,7 @@ class Keg def remove_oldname_opt_record return unless oldname_opt_record - return unless oldname_opt_record.resolved_path == path + return if oldname_opt_record.resolved_path != path @oldname_opt_record.unlink @oldname_opt_record.parent.rmdir_if_possible