Compare against HOMEBREW_CELLAR using real paths.
The code in Keg.self.for path uses "path = path.parent.realpath" to walk up subfolders looking for a Keg. Because 'realpath' is in there, and the path is checked against HOMEBREW_CELLAR, which may be a symlink, we need to do realpath-to-realpath comparisons in Keg. Otherwise, we will hit equivalent but symlinked folders, not see that they are the same, and walk all the way up to / and then error out.
This commit is contained in:
parent
55f7b826d9
commit
bc378d091b
@ -24,14 +24,15 @@
|
|||||||
class Keg <Pathname
|
class Keg <Pathname
|
||||||
def initialize path
|
def initialize path
|
||||||
super path
|
super path
|
||||||
raise "#{to_s} is not a valid keg" unless parent.parent == HOMEBREW_CELLAR
|
raise "#{to_s} is not a valid keg" unless parent.parent.realpath == HOMEBREW_CELLAR.realpath
|
||||||
raise "#{to_s} is not a directory" unless directory?
|
raise "#{to_s} is not a directory" unless directory?
|
||||||
end
|
end
|
||||||
|
|
||||||
# if path is a file in a keg then this will return the containing Keg object
|
# if path is a file in a keg then this will return the containing Keg object
|
||||||
def self.for path
|
def self.for path
|
||||||
|
path = path.realpath
|
||||||
while not path.root?
|
while not path.root?
|
||||||
return Keg.new(path) if path.parent.parent == HOMEBREW_CELLAR
|
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 "#{path} is not inside a keg"
|
raise "#{path} is not inside a keg"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user