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: fix alias and versioned symlink handling. #10327

Merged
merged 2 commits into from Jan 14, 2021
Merged
Show file tree
Hide file tree
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
31 changes: 14 additions & 17 deletions Library/Homebrew/keg.rb
Expand Up @@ -301,28 +301,16 @@ def remove_old_aliases
# versioned aliases are handled below
next if a.match?(/.+@./)

alias_opt_symlink = opt/a
if alias_opt_symlink.symlink? && alias_opt_symlink.exist?
alias_opt_symlink.delete if alias_opt_symlink.realpath == opt_record.realpath
elsif alias_opt_symlink.symlink? || alias_opt_symlink.exist?
alias_opt_symlink.delete
end

alias_linkedkegs_symlink = linkedkegs/a
alias_linkedkegs_symlink.delete if alias_linkedkegs_symlink.symlink? || alias_linkedkegs_symlink.exist?
remove_alias_symlink(opt/a, opt_record)
remove_alias_symlink(linkedkegs/a, linked_keg_record)
end

Pathname.glob("#{opt_record}@*").each do |a|
a = a.basename.to_s
next if aliases.include?(a)

alias_opt_symlink = opt/a
if alias_opt_symlink.symlink? && alias_opt_symlink.exist? && rack == alias_opt_symlink.realpath.parent
alias_opt_symlink.delete
end

alias_linkedkegs_symlink = linkedkegs/a
alias_linkedkegs_symlink.delete if alias_linkedkegs_symlink.symlink? || alias_linkedkegs_symlink.exist?
remove_alias_symlink(opt/a, rack)
remove_alias_symlink(linkedkegs/a, rack)
end
end

Expand All @@ -341,6 +329,7 @@ def uninstall
path.rmtree
path.parent.rmdir_if_possible
remove_opt_record if optlinked?
remove_linked_keg_record if linked?
remove_old_aliases
remove_oldname_opt_record
rescue Errno::EACCES, Errno::ENOTEMPTY
Expand Down Expand Up @@ -377,12 +366,12 @@ def unlink(**options)

dst.uninstall_info if dst.to_s.match?(INFOFILE_RX)
dst.unlink
remove_old_aliases
Find.prune if src.directory?
end
end

unless options[:dry_run]
remove_old_aliases
remove_linked_keg_record if linked?
dirs.reverse_each(&:rmdir_if_possible)
end
Expand Down Expand Up @@ -659,6 +648,14 @@ def make_relative_symlink(dst, src, **options)
raise LinkError.new(self, src.relative_path_from(path), dst, e)
end

def remove_alias_symlink(alias_symlink, alias_match_path)
if alias_symlink.symlink? && alias_symlink.exist?
alias_symlink.delete if alias_symlink.realpath == alias_match_path.realpath
elsif alias_symlink.symlink? || alias_symlink.exist?
alias_symlink.delete
end
end

protected

# symlinks the contents of path+relative_dir recursively into #{HOMEBREW_PREFIX}/relative_dir
Expand Down
7 changes: 6 additions & 1 deletion Library/Homebrew/tab.rb
Expand Up @@ -58,7 +58,12 @@ def self.create(formula, compiler, stdlib)
# Returns the {Tab} for an install receipt at `path`.
# Results are cached.
def self.from_file(path)
cache.fetch(path) { |p| cache[p] = from_file_content(File.read(p), p) }
cache.fetch(path) do |p|
content = File.read(p)
return empty if content.blank?

cache[p] = from_file_content(content, p)
end
end

# Like {from_file}, but bypass the cache.
Expand Down