aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/formula_pin.rb
diff options
context:
space:
mode:
authorSimon Sigurdhsson2013-03-11 16:41:08 +0100
committerMike McQuaid2013-03-30 19:50:47 +0000
commit85eb73ced7316171a3e5087e601f3c182b8859ed (patch)
treed48851b6277651af254f603198b0f38270745cff /Library/Homebrew/formula_pin.rb
parentee7224c8ecb8e6d58b3bc40aee962d81035bf3b9 (diff)
downloadhomebrew-85eb73ced7316171a3e5087e601f3c182b8859ed.tar.bz2
brew-pin: prevent selected formulae from upgrade.
* Added `pin` et. al. to manpage. * Added `brew pin` to `brew.1` * Added `brew unpin` to `brew.1` * Added `brew list --pinned` to `brew.1` * Added information about frozen formulae to `brew upgrade` in `brew.1` * Added `pin` et.al. to completion scripts. * Unpin formulae when uninstalling them * Unpin and re-pin formulae when upgrading (avoids stale symlink) References #18386. Closes #18515. Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
Diffstat (limited to 'Library/Homebrew/formula_pin.rb')
-rw-r--r--Library/Homebrew/formula_pin.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/Library/Homebrew/formula_pin.rb b/Library/Homebrew/formula_pin.rb
new file mode 100644
index 000000000..cdffd7fc0
--- /dev/null
+++ b/Library/Homebrew/formula_pin.rb
@@ -0,0 +1,36 @@
+require 'formula'
+require 'fileutils'
+
+class FormulaPin
+ HOMEBREW_PINNED = HOMEBREW_LIBRARY/'PinnedKegs'
+
+ def initialize(formula)
+ @formula = formula
+ @name = formula.name
+ HOMEBREW_PINNED.mkdir unless HOMEBREW_PINNED.exist?
+ @path = HOMEBREW_PINNED/@name
+ end
+
+ def pin_at(version)
+ version_path = @formula.installed_prefix.parent.join(version)
+ FileUtils.ln_s version_path, @path unless pinned? or not version_path.exist?
+ end
+
+ def pin
+ versions = @formula.installed_prefix.parent.children.map { |item| item.basename.to_s }
+ version = versions.map { |item| Version.new(item) }.sort[0].to_s
+ pin_at(version)
+ end
+
+ def unpin
+ FileUtils.rm @path if pinned?
+ end
+
+ def pinned?
+ @path.exist?
+ end
+
+ def pinable?
+ @formula.installed_prefix.parent.children.length > 0
+ end
+end