Skip to content

Commit

Permalink
Allow multiple formula to symlink the same directory
Browse files Browse the repository at this point in the history
During the link step, if the destination symlink already exists, unlink it, and create a directory instead, then relink the original contents. Then continue linking the formula in question.

Fixes Homebrew#62
  • Loading branch information
mxcl committed Oct 23, 2009
1 parent a6f0ac4 commit 515f48c
Showing 1 changed file with 37 additions and 6 deletions.
43 changes: 37 additions & 6 deletions Library/Homebrew/keg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ def initialize path
raise "#{to_s} is not a directory" unless directory?
end

# if path is a file in a keg then this will return the containing Keg object
def self.for path
while not path.root?
return Keg.new(path) if path.parent.parent == HOMEBREW_CELLAR
path = path.parent.realpath # realpath() prevents root? failing
end
raise "#{path} is not inside a keg"
end

def uninstall
chmod_R 0777 # ensure we have permission to delete
rmtree
Expand Down Expand Up @@ -72,28 +81,50 @@ def link
return $n+$d
end
private
protected
def resolve_any_conflicts dst
# if it isn't a directory then a severe conflict is about to happen. Let
# it, and the exception that is generated will message to the user about
# the situation
if dst.symlink? and dst.directory?
src = (dst.parent+dst.readlink).cleanpath
keg = Keg.for(src)
dst.unlink
keg.link_dir(src) { :mkpath }
return true
end
end
# symlinks the contents of self+foo recursively into /usr/local/foo
def link_dir foo
root=self+foo
root = self+foo
root.find do |src|
next if src == root
dst=HOMEBREW_PREFIX+src.relative_path_from(self)
dst = HOMEBREW_PREFIX+src.relative_path_from(self)
dst.extend ObserverPathnameExtension
if src.file?
dst.make_relative_symlink src
elsif src.directory?
# if the dst dir already exists, then great! walk the rest of the tree tho
next if dst.directory? and not dst.symlink?
# no need to put .app bundles in the path, the user can just use
# spotlight, or the open command and actual mac apps use an equivalent
Find.prune if src.extname.to_s == '.app'
case yield src.relative_path_from(root)
when :skip then Find.prune
when :mkpath then dst.mkpath
else dst.make_relative_symlink src; Find.prune
when :skip
Find.prune
when :mkpath
dst.mkpath unless resolve_any_conflicts(dst)
else
unless resolve_any_conflicts(dst)
dst.make_relative_symlink(src)
Find.prune
end
end
end
end
Expand Down

0 comments on commit 515f48c

Please sign in to comment.