Merge pull request #2923 from MikeMcQuaid/alias-fixes

keg: correctly cleanup old aliases.
This commit is contained in:
Mike McQuaid 2017-07-30 16:02:49 +01:00 committed by GitHub
commit e8c4989efb
4 changed files with 39 additions and 12 deletions

View File

@ -383,7 +383,9 @@ class Formula
# All of aliases for the formula # All of aliases for the formula
def aliases def aliases
@aliases ||= if tap @aliases ||= if tap
tap.alias_reverse_table[full_name] || [] tap.alias_reverse_table[full_name].to_a.map do |a|
a.split("/")[-1]
end
else else
[] []
end end

View File

@ -865,6 +865,7 @@ class FormulaInstaller
tab.source["path"] = formula.specified_path.to_s tab.source["path"] = formula.specified_path.to_s
tab.installed_as_dependency = installed_as_dependency tab.installed_as_dependency = installed_as_dependency
tab.installed_on_request = installed_on_request tab.installed_on_request = installed_on_request
tab.aliases = formula.aliases
tab.write tab.write
end end

View File

@ -237,13 +237,37 @@ class Keg
opt_record.symlink? && path == opt_record.resolved_path opt_record.symlink? && path == opt_record.resolved_path
end end
def remove_opt_record def remove_old_aliases
opt_record.unlink opt = opt_record.parent
aliases.each do |a|
alias_symlink = opt_record.parent/a tap = begin
next if !alias_symlink.symlink? && !alias_symlink.exist? to_formula.tap
rescue FormulaUnavailableError, TapFormulaAmbiguityError,
TapFormulaWithOldnameAmbiguityError
# If the formula can't be found, just ignore aliases for now.
nil
end
if tap
bad_tap_opt = opt/tap.user
FileUtils.rm_rf bad_tap_opt if bad_tap_opt.directory?
end
Pathname.glob("#{opt_record}@*").each do |a|
a = a.basename
next if aliases.include?(a)
alias_symlink = opt/a
if alias_symlink.symlink? && alias_symlink.exist?
next if rack != alias_symlink.realpath.parent
end
alias_symlink.delete alias_symlink.delete
end end
end
def remove_opt_record
opt_record.unlink
opt_record.parent.rmdir_if_possible opt_record.parent.rmdir_if_possible
end end
@ -251,6 +275,7 @@ class Keg
path.rmtree path.rmtree
path.parent.rmdir_if_possible path.parent.rmdir_if_possible
remove_opt_record if optlinked? remove_opt_record if optlinked?
remove_old_aliases
remove_oldname_opt_record remove_oldname_opt_record
end end
@ -277,6 +302,7 @@ class Keg
dst.uninstall_info if dst.to_s =~ INFOFILE_RX dst.uninstall_info if dst.to_s =~ INFOFILE_RX
dst.unlink dst.unlink
remove_old_aliases
Find.prune if src.directory? Find.prune if src.directory?
end end
end end
@ -468,12 +494,7 @@ class Keg
end end
def aliases def aliases
formula = Formulary.from_rack(rack) Tab.for_keg(self).aliases || []
aliases = formula.aliases
return aliases if formula.stable?
aliases.reject { |a| a.include?("@") }
rescue FormulaUnavailableError
[]
end end
def optlink(mode = OpenStruct.new) def optlink(mode = OpenStruct.new)

View File

@ -33,6 +33,7 @@ class Tab < OpenStruct
"HEAD" => HOMEBREW_REPOSITORY.git_head, "HEAD" => HOMEBREW_REPOSITORY.git_head,
"compiler" => compiler, "compiler" => compiler,
"stdlib" => stdlib, "stdlib" => stdlib,
"aliases" => formula.aliases,
"runtime_dependencies" => formula.runtime_dependencies.map do |dep| "runtime_dependencies" => formula.runtime_dependencies.map do |dep|
f = dep.to_formula f = dep.to_formula
{ "full_name" => f.full_name, "version" => f.version.to_s } { "full_name" => f.full_name, "version" => f.version.to_s }
@ -185,6 +186,7 @@ class Tab < OpenStruct
"HEAD" => nil, "HEAD" => nil,
"stdlib" => nil, "stdlib" => nil,
"compiler" => DevelopmentTools.default_compiler, "compiler" => DevelopmentTools.default_compiler,
"aliases" => [],
"runtime_dependencies" => [], "runtime_dependencies" => [],
"source" => { "source" => {
"path" => nil, "path" => nil,
@ -328,6 +330,7 @@ class Tab < OpenStruct
"HEAD" => self.HEAD, "HEAD" => self.HEAD,
"stdlib" => (stdlib.to_s if stdlib), "stdlib" => (stdlib.to_s if stdlib),
"compiler" => (compiler.to_s if compiler), "compiler" => (compiler.to_s if compiler),
"aliases" => aliases,
"runtime_dependencies" => runtime_dependencies, "runtime_dependencies" => runtime_dependencies,
"source" => source, "source" => source,
} }