Skip to content
Snippets Groups Projects
Commit 8472d6a4 authored by Mike McQuaid's avatar Mike McQuaid
Browse files

formula: check installed_alias_path exists.

Otherwise return `nil`.

Fixes https://github.com/Homebrew/brew/issues/2417
parent c69e4ee2
No related branches found
No related tags found
No related merge requests found
......@@ -252,12 +252,14 @@ class Formula
public
# The alias path that was used to install this formula, if present.
# The alias path that was used to install this formula, if it exists.
# Can differ from alias_path, which is the alias used to find the formula,
# and is specified to this instance.
def installed_alias_path
path = build.source["path"] if build.is_a?(Tab)
path if path =~ %r{#{HOMEBREW_TAP_DIR_REGEX}/Aliases}
return unless path =~ %r{#{HOMEBREW_TAP_DIR_REGEX}/Aliases}
return unless File.symlink?(path)
path
end
def installed_alias_name
......
......@@ -129,6 +129,8 @@ describe Formula do
alias_name = "bar"
alias_path = "#{CoreTap.instance.alias_dir}/#{alias_name}"
CoreTap.instance.alias_dir.mkpath
FileUtils.ln_sf f.path, alias_path
f.build = Tab.new(source: { "path" => alias_path })
......@@ -160,6 +162,8 @@ describe Formula do
alias_name = "bar"
full_alias_name = "#{tap.user}/#{tap.repo}/#{alias_name}"
alias_path = "#{tap.alias_dir}/#{alias_name}"
tap.alias_dir.mkpath
FileUtils.ln_sf f.path, alias_path
f.build = Tab.new(source: { "path" => alias_path })
......@@ -168,6 +172,8 @@ describe Formula do
expect(f.full_installed_alias_name).to eq(full_alias_name)
expect(f.installed_specified_name).to eq(alias_name)
expect(f.full_installed_specified_name).to eq(full_alias_name)
FileUtils.rm_rf HOMEBREW_LIBRARY/"Taps/user"
end
specify "#prefix" do
......@@ -402,6 +408,8 @@ describe Formula do
url "foo-1.0"
end
f.build = Tab.new(source: { "path" => source_path.to_s })
CoreTap.instance.alias_dir.mkpath
FileUtils.ln_sf f.path, source_path
expect(f.alias_path).to eq(alias_path)
expect(f.installed_alias_path).to eq(source_path.to_s)
......@@ -443,6 +451,9 @@ describe Formula do
allow(described_class).to receive(:installed).and_return(formulae)
CoreTap.instance.alias_dir.mkpath
FileUtils.ln_sf formula_with_alias.path, alias_path
expect(described_class.installed_with_alias_path(alias_path))
.to eq([formula_with_alias])
end
......@@ -940,6 +951,9 @@ describe Formula do
tab.source["path"] = alias_path
stub_formula_loader(f, alias_path)
CoreTap.instance.alias_dir.mkpath
FileUtils.ln_sf f.path, alias_path
expect(f.current_installed_alias_target).to eq(f)
expect(f.latest_formula).to eq(f)
expect(f).not_to have_changed_installed_alias_target
......@@ -952,6 +966,9 @@ describe Formula do
tab.source["path"] = alias_path
stub_formula_loader(new_formula, alias_path)
CoreTap.instance.alias_dir.mkpath
FileUtils.ln_sf new_formula.path, alias_path
expect(f.current_installed_alias_target).to eq(new_formula)
expect(f.latest_formula).to eq(new_formula)
expect(f).to have_changed_installed_alias_target
......@@ -964,6 +981,9 @@ describe Formula do
tab.source["path"] = alias_path
stub_formula_loader(new_formula, alias_path)
CoreTap.instance.alias_dir.mkpath
FileUtils.ln_sf new_formula.path, alias_path
expect(new_formula.current_installed_alias_target).to eq(new_formula)
expect(new_formula.latest_formula).to eq(new_formula)
expect(new_formula).not_to have_changed_installed_alias_target
......@@ -1050,6 +1070,10 @@ describe Formula do
f.follow_installed_alias = true
f.build = setup_tab_for_prefix(same_prefix, path: alias_path)
stub_formula_loader(new_formula, alias_path)
CoreTap.instance.alias_dir.mkpath
FileUtils.ln_sf new_formula.path, alias_path
expect(f.outdated_kegs).not_to be_empty
end
......@@ -1088,6 +1112,10 @@ describe Formula do
tab = setup_tab_for_prefix(old_alias_target_prefix, path: alias_path)
old_formula.build = tab
allow(described_class).to receive(:installed).and_return([old_formula])
CoreTap.instance.alias_dir.mkpath
FileUtils.ln_sf f.path, alias_path
expect(f.outdated_kegs).not_to be_empty
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment