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

formulary: fix to_rack for fully-scoped references

Fixes the case where I have `mysql56` installed but do
`brew uninstall foo/bar/mysql56` which isn't a valid formula.

Fixes https://github.com/Homebrew/legacy-homebrew/issues/39883.
parent ffd71d02
No related branches found
No related tags found
No related merge requests found
...@@ -256,12 +256,15 @@ class Formulary ...@@ -256,12 +256,15 @@ class Formulary
end end
def self.to_rack(ref) def self.to_rack(ref)
# First, check whether the rack with the given name exists. # If using a fully-scoped reference, check if the formula can be resolved.
factory(ref) if ref.include? "/"
# Check whether the rack with the given name exists.
if (rack = HOMEBREW_CELLAR/File.basename(ref, ".rb")).directory? if (rack = HOMEBREW_CELLAR/File.basename(ref, ".rb")).directory?
return rack.resolved_path return rack.resolved_path
end end
# Second, use canonical name to locate rack. # Use canonical name to locate rack.
(HOMEBREW_CELLAR/canonical_name(ref)).resolved_path (HOMEBREW_CELLAR/canonical_name(ref)).resolved_path
end end
......
...@@ -111,6 +111,15 @@ class FormularyFactoryTest < Homebrew::TestCase ...@@ -111,6 +111,15 @@ class FormularyFactoryTest < Homebrew::TestCase
def test_load_from_contents def test_load_from_contents
assert_kind_of Formula, Formulary.from_contents(@name, @path, @path.read) assert_kind_of Formula, Formulary.from_contents(@name, @path, @path.read)
end end
def test_to_rack
assert_equal HOMEBREW_CELLAR/@name, Formulary.to_rack(@name)
(HOMEBREW_CELLAR/@name).mkpath
assert_equal HOMEBREW_CELLAR/@name, Formulary.to_rack(@name)
assert_raises(TapFormulaUnavailableError) { Formulary.to_rack("a/b/#{@name}") }
ensure
FileUtils.rm_rf HOMEBREW_CELLAR/@name
end
end end
class FormularyTapFactoryTest < Homebrew::TestCase class FormularyTapFactoryTest < Homebrew::TestCase
......
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