Skip to content

Commit

Permalink
Keg.for: handle non-existent path.
Browse files Browse the repository at this point in the history
Otherwise `path.realpath` will raise `Errno::ENOENT` rather than the
expected `NotAKegError`.

Fixes #9015
  • Loading branch information
MikeMcQuaid committed Nov 2, 2020
1 parent 4ecd5d9 commit b54b022
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions Library/Homebrew/keg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,15 @@ def self.find_some_installed_dependents(kegs)

# 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
Expand Down

0 comments on commit b54b022

Please sign in to comment.