Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keg.for: handle non-existent path. #9031

Merged
merged 1 commit into from
Nov 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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