From 0bb33f8b10886277845d1193f7139307cdceed57 Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Sun, 14 Apr 2013 21:32:30 -0500 Subject: Avoid slow operations in FormulaPin#initialize A FormulaPin object is created every time Formula is instantiated, so don't do filesystem operations or Pathname concatenation eagerly. --- Library/Homebrew/formula_pin.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'Library/Homebrew/formula_pin.rb') diff --git a/Library/Homebrew/formula_pin.rb b/Library/Homebrew/formula_pin.rb index c809a02b8..c6740f104 100644 --- a/Library/Homebrew/formula_pin.rb +++ b/Library/Homebrew/formula_pin.rb @@ -6,13 +6,16 @@ class FormulaPin def initialize(formula) @formula = formula @name = formula.name - HOMEBREW_PINNED.mkdir unless HOMEBREW_PINNED.exist? - @path = HOMEBREW_PINNED+@name + end + + def path + HOMEBREW_PINNED+@name end def pin_at(version) + HOMEBREW_PINNED.mkpath unless HOMEBREW_PINNED.exist? version_path = @formula.installed_prefix.parent.join(version) - FileUtils.ln_s version_path, @path unless pinned? or not version_path.exist? + FileUtils.ln_s version_path, path unless pinned? or not version_path.exist? end def pin @@ -22,11 +25,11 @@ class FormulaPin end def unpin - FileUtils.rm @path if pinned? + FileUtils.rm path if pinned? end def pinned? - @path.symlink? + path.symlink? end def pinable? -- cgit v1.2.3