2014-06-21 18:20:51 -05:00
|
|
|
require "keg"
|
|
|
|
|
2013-03-11 16:41:08 +01:00
|
|
|
class FormulaPin
|
2013-04-16 01:43:26 -05:00
|
|
|
PINDIR = Pathname.new("#{HOMEBREW_LIBRARY}/PinnedKegs")
|
2013-03-11 16:41:08 +01:00
|
|
|
|
2013-04-16 01:43:26 -05:00
|
|
|
def initialize(f)
|
|
|
|
@f = f
|
2013-04-14 21:32:30 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def path
|
2013-04-16 01:43:26 -05:00
|
|
|
Pathname.new("#{PINDIR}/#{@f.name}")
|
2013-03-11 16:41:08 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def pin_at(version)
|
2014-06-21 18:19:36 -05:00
|
|
|
PINDIR.mkpath
|
2013-04-16 01:43:26 -05:00
|
|
|
version_path = @f.rack.join(version)
|
2014-06-21 18:19:36 -05:00
|
|
|
path.make_relative_symlink(version_path) unless pinned? || !version_path.exist?
|
2013-03-11 16:41:08 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def pin
|
2015-11-29 15:38:40 +08:00
|
|
|
pin_at(@f.installed_kegs.map { |keg| keg.version }.max)
|
2013-03-11 16:41:08 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def unpin
|
2014-06-21 18:19:36 -05:00
|
|
|
path.unlink if pinned?
|
2014-06-23 21:48:15 -05:00
|
|
|
PINDIR.rmdir_if_possible
|
2013-03-11 16:41:08 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def pinned?
|
2013-04-14 21:32:30 -05:00
|
|
|
path.symlink?
|
2013-03-11 16:41:08 +01:00
|
|
|
end
|
|
|
|
|
2013-04-16 01:43:26 -05:00
|
|
|
def pinnable?
|
2015-11-29 15:38:40 +08:00
|
|
|
@f.installed_prefixes.any?
|
2013-03-11 16:41:08 +01:00
|
|
|
end
|
2015-11-16 19:23:48 +08:00
|
|
|
|
|
|
|
def pinned_version
|
|
|
|
Keg.new(path.resolved_path).version if pinned?
|
|
|
|
end
|
2013-03-11 16:41:08 +01:00
|
|
|
end
|