2009-08-31 16:01:36 +01:00
|
|
|
# Copyright 2009 Max Howell and other contributors.
|
2009-07-24 15:10:01 +01:00
|
|
|
#
|
2009-08-31 16:01:36 +01:00
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
2009-07-24 15:10:01 +01:00
|
|
|
#
|
2009-08-31 16:01:36 +01:00
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
2009-07-24 15:10:01 +01:00
|
|
|
#
|
2009-08-31 16:01:36 +01:00
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2009-08-10 16:48:30 +01:00
|
|
|
#
|
|
|
|
class Keg <Pathname
|
|
|
|
def initialize path
|
|
|
|
super path
|
2009-11-12 11:09:20 -08:00
|
|
|
raise "#{to_s} is not a valid keg" unless parent.parent.realpath == HOMEBREW_CELLAR.realpath
|
2009-08-10 16:48:30 +01:00
|
|
|
raise "#{to_s} is not a directory" unless directory?
|
|
|
|
end
|
2009-07-24 15:10:01 +01:00
|
|
|
|
2009-10-23 16:03:38 +01:00
|
|
|
# if path is a file in a keg then this will return the containing Keg object
|
|
|
|
def self.for path
|
2009-11-12 11:09:20 -08:00
|
|
|
path = path.realpath
|
2009-10-23 16:03:38 +01:00
|
|
|
while not path.root?
|
2009-11-12 11:09:20 -08:00
|
|
|
return Keg.new(path) if path.parent.parent == HOMEBREW_CELLAR.realpath
|
2009-10-23 16:03:38 +01:00
|
|
|
path = path.parent.realpath # realpath() prevents root? failing
|
|
|
|
end
|
|
|
|
raise "#{path} is not inside a keg"
|
|
|
|
end
|
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
def uninstall
|
|
|
|
chmod_R 0777 # ensure we have permission to delete
|
|
|
|
rmtree
|
|
|
|
parent.rmdir_if_possible
|
2009-07-24 15:10:01 +01:00
|
|
|
end
|
|
|
|
|
2009-08-29 21:07:26 +01:00
|
|
|
def unlink
|
|
|
|
n=0
|
|
|
|
Pathname.new(self).find do |src|
|
|
|
|
next if src == self
|
|
|
|
dst=HOMEBREW_PREFIX+src.relative_path_from(self)
|
|
|
|
next unless dst.symlink?
|
|
|
|
dst.unlink
|
|
|
|
n+=1
|
|
|
|
Find.prune if src.directory?
|
|
|
|
end
|
|
|
|
n
|
|
|
|
end
|
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
def link
|
|
|
|
$n=0
|
|
|
|
$d=0
|
2009-07-24 15:10:01 +01:00
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
mkpaths=(1..9).collect {|x| "man/man#{x}"} <<'man'<<'doc'<<'locale'<<'info'<<'aclocal'
|
2009-07-24 15:10:01 +01:00
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
# yeah indeed, you have to force anything you need in the main tree into
|
|
|
|
# these dirs REMEMBER that *NOT* everything needs to be in the main tree
|
|
|
|
link_dir('etc') {:mkpath}
|
2009-08-23 19:05:42 +01:00
|
|
|
link_dir('bin') {:skip}
|
2009-08-12 09:43:16 +08:00
|
|
|
link_dir('sbin') {:link}
|
2009-08-10 16:48:30 +01:00
|
|
|
link_dir('include') {:link}
|
|
|
|
link_dir('share') {|path| :mkpath if mkpaths.include? path.to_s}
|
2009-07-29 00:56:22 +01:00
|
|
|
|
2009-09-17 21:26:17 +01:00
|
|
|
link_dir('lib') do |path|
|
|
|
|
case path.to_s
|
|
|
|
when /^pkgconfig/ then :mkpath
|
|
|
|
when /^php/ then :mkpath
|
|
|
|
when /^perl5/ then :mkpath
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
return $n+$d
|
2009-07-24 15:10:01 +01:00
|
|
|
end
|
|
|
|
|
2009-10-23 16:03:38 +01:00
|
|
|
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
|
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
# symlinks the contents of self+foo recursively into /usr/local/foo
|
|
|
|
def link_dir foo
|
2009-10-23 16:03:38 +01:00
|
|
|
root = self+foo
|
2009-07-24 15:10:01 +01:00
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
root.find do |src|
|
|
|
|
next if src == root
|
2009-07-24 15:10:01 +01:00
|
|
|
|
2009-10-23 16:03:38 +01:00
|
|
|
dst = HOMEBREW_PREFIX+src.relative_path_from(self)
|
2009-08-10 16:48:30 +01:00
|
|
|
dst.extend ObserverPathnameExtension
|
2009-07-24 15:10:01 +01:00
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
if src.file?
|
|
|
|
dst.make_relative_symlink src
|
|
|
|
elsif src.directory?
|
2009-10-23 16:03:38 +01:00
|
|
|
# if the dst dir already exists, then great! walk the rest of the tree tho
|
|
|
|
next if dst.directory? and not dst.symlink?
|
|
|
|
|
2009-07-24 15:10:01 +01:00
|
|
|
# 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
|
2009-08-10 16:48:30 +01:00
|
|
|
Find.prune if src.extname.to_s == '.app'
|
2009-07-24 15:10:01 +01:00
|
|
|
|
2009-08-10 16:48:30 +01:00
|
|
|
case yield src.relative_path_from(root)
|
2009-10-23 16:03:38 +01:00
|
|
|
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
|
2009-07-24 15:10:01 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2009-08-10 16:48:30 +01:00
|
|
|
end
|