forked from Homebrew/legacy-homebrew
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 Homebrew#18386. Closes Homebrew#18515. Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
- Loading branch information
1 parent
480072c
commit 1e76317
Showing
13 changed files
with
168 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require 'formula' | ||
|
||
module Homebrew extend self | ||
def pin | ||
if Process.uid.zero? and not File.stat(HOMEBREW_BREW_FILE).uid.zero? | ||
abort "Cowardly refusing to `sudo pin'" | ||
end | ||
raise FormulaUnspecifiedError if ARGV.named.empty? | ||
ARGV.formulae.each do |fmla| | ||
f = Formula.factory(fmla.to_s) | ||
onoe "Cannot pin uninstalled formula #{f.name}!" unless f.pinable? | ||
opoo "Formula #{f.name} already pinned!" if f.pinable? and f.pinned? | ||
f.pin if f.pinable? and not f.pinned? | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require 'formula' | ||
|
||
module Homebrew extend self | ||
def unpin | ||
if Process.uid.zero? and not File.stat(HOMEBREW_BREW_FILE).uid.zero? | ||
abort "Cowardly refusing to `sudo unpin'" | ||
end | ||
raise FormulaUnspecifiedError if ARGV.named.empty? | ||
ARGV.formulae.each do |fmla| | ||
f = Formula.factory(fmla.to_s) | ||
onoe "Cannot unpin uninstalled formula #{f.name}!" unless f.pinable? | ||
opoo "Formula #{f.name} already unpinned!" if f.pinable? and not f.pinned? | ||
f.unpin if f.pinable? and f.pinned? | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.