Store the opt record so we don't have to keep reconstructing it

This commit is contained in:
Jack Nagel 2014-06-30 20:16:01 -05:00
parent 30e273c2d1
commit 0744ed9410
2 changed files with 13 additions and 14 deletions

View File

@ -88,7 +88,7 @@ class Keg
raise NotAKegError, "#{path} is not inside a keg" raise NotAKegError, "#{path} is not inside a keg"
end end
attr_reader :path, :name, :linked_keg_record attr_reader :path, :name, :linked_keg_record, :opt_record
protected :path protected :path
def initialize path def initialize path
@ -97,6 +97,7 @@ class Keg
@path = path @path = path
@name = path.parent.basename.to_s @name = path.parent.basename.to_s
@linked_keg_record = HOMEBREW_LIBRARY.join("LinkedKegs", name) @linked_keg_record = HOMEBREW_LIBRARY.join("LinkedKegs", name)
@opt_record = HOMEBREW_PREFIX.join("opt", name)
end end
def fname def fname
@ -166,10 +167,9 @@ class Keg
path.rmtree path.rmtree
path.parent.rmdir_if_possible path.parent.rmdir_if_possible
opt = HOMEBREW_PREFIX.join("opt", name) if opt_record.symlink? && path == opt_record.resolved_path
if opt.symlink? && path == opt.resolved_path opt_record.unlink
opt.unlink opt_record.parent.rmdir_if_possible
opt.parent.rmdir_if_possible
end end
end end
@ -306,15 +306,14 @@ class Keg
end end
def optlink def optlink
from = HOMEBREW_PREFIX.join("opt", name) if opt_record.symlink?
if from.symlink? opt_record.delete
from.delete elsif opt_record.directory?
elsif from.directory? opt_record.rmdir
from.rmdir elsif opt_record.exist?
elsif from.exist? opt_record.delete
from.delete
end end
make_relative_symlink(from, path) make_relative_symlink(opt_record, path)
end end
def delete_pyc_files! def delete_pyc_files!

View File

@ -141,7 +141,7 @@ class Keg
if shortpath.exist? and not options[:keg_only] if shortpath.exist? and not options[:keg_only]
shortpath.to_s shortpath.to_s
else else
HOMEBREW_PREFIX.join("opt", name, relative_dirname, basename).to_s opt_record.join(relative_dirname, basename).to_s
end end
end end