Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keg: general cleanup. #7957

Merged
merged 1 commit into from
Jul 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 7 additions & 6 deletions Library/Homebrew/keg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def self.all

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
Expand Down Expand Up @@ -322,17 +322,18 @@ def unlink(mode = OpenStruct.new)

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)

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
Expand Down Expand Up @@ -509,7 +510,7 @@ def link(mode = OpenStruct.new)

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
Expand Down