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

Keg.for: handle non-existent path.

Otherwise `path.realpath` will raise `Errno::ENOENT` rather than the
expected `NotAKegError`.

Fixes https://github.com/Homebrew/brew/issues/9015
parent 4ecd5d98
No related branches found
No related tags found
No related merge requests found
......@@ -183,13 +183,15 @@ class Keg
# if path is a file in a keg then this will return the containing Keg object
def self.for(path)
path = path.realpath
until path.root?
return Keg.new(path) if path.parent.parent == HOMEBREW_CELLAR.realpath
original_path = path
if original_path.exist? && (path = original_path.realpath)
until path.root?
return Keg.new(path) if path.parent.parent == HOMEBREW_CELLAR.realpath
path = path.parent.realpath # realpath() prevents root? failing
path = path.parent.realpath # realpath() prevents root? failing
end
end
raise NotAKegError, "#{path} is not inside a keg"
raise NotAKegError, "#{original_path} is not inside a keg"
end
def self.all
......
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