diff options
| author | Mike McQuaid | 2017-03-29 11:19:25 +0100 |
|---|---|---|
| committer | Mike McQuaid | 2017-03-31 10:01:45 +0100 |
| commit | 5d1f4dd531f9e88c762f2f65e73e67511798c62d (patch) | |
| tree | 2e9ff9dd193b44f8ec419375d6aee20cf745ba88 /Library | |
| parent | 80b39bb23917d9b80bb80eb15a890607d69e65b6 (diff) | |
| download | brew-5d1f4dd531f9e88c762f2f65e73e67511798c62d.tar.bz2 | |
migrator: add more helper methods.
Add methods to determine if a migration is needed and perform it if so
(and no-op if not). Additionally, make `ARGV.force?` get passed as a
parameter so it can be overridden without requiring users to pass
`—force`.
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/migrator.rb | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/Library/Homebrew/migrator.rb b/Library/Homebrew/migrator.rb index a58ca2059..44614d553 100644 --- a/Library/Homebrew/migrator.rb +++ b/Library/Homebrew/migrator.rb @@ -83,7 +83,26 @@ class Migrator # path to newname keg that will be linked if old_linked_keg isn't nil attr_reader :new_linked_keg_record - def initialize(formula) + def self.needs_migration?(formula) + oldname = formula.oldname + return false unless oldname + oldname_rack = HOMEBREW_CELLAR/oldname + return false if oldname_rack.symlink? + return false unless oldname_rack.directory? + true + end + + def self.migrate_if_needed(formula) + return unless Migrator.needs_migration?(formula) + begin + migrator = Migrator.new(formula, force: true) + migrator.migrate + rescue Exception => e + onoe e + end + end + + def initialize(formula, force: ARGV.force?) @oldname = formula.oldname @newname = formula.name raise MigratorNoOldnameError, formula unless oldname @@ -95,7 +114,7 @@ class Migrator @old_tabs = old_cellar.subdirs.map { |d| Tab.for_keg(Keg.new(d)) } @old_tap = old_tabs.first.tap - if !ARGV.force? && !from_same_taps? + if !force && !from_same_taps? raise MigratorDifferentTapsError.new(formula, old_tap) end |
