diff options
| author | Mike McQuaid | 2017-03-29 11:21:31 +0100 |
|---|---|---|
| committer | Mike McQuaid | 2017-03-31 10:01:45 +0100 |
| commit | 1606e5db6fa91fae8eb32d876e100f3835ec099a (patch) | |
| tree | 8c2095c6b34451093c35267c0aee2ed7f9c8fd52 | |
| parent | 5d1f4dd531f9e88c762f2f65e73e67511798c62d (diff) | |
| download | brew-1606e5db6fa91fae8eb32d876e100f3835ec099a.tar.bz2 | |
migrator: move around some migration logic.
Move the checks for moving kegs to a new directory into the relevant
method (`move_to_new_directory`) instead. Also, delete duplicated
directories when we’ve confirmed they are definitely duplicated rather
than telling users to do so.
| -rw-r--r-- | Library/Homebrew/migrator.rb | 60 |
1 files changed, 32 insertions, 28 deletions
diff --git a/Library/Homebrew/migrator.rb b/Library/Homebrew/migrator.rb index 44614d553..96121ee32 100644 --- a/Library/Homebrew/migrator.rb +++ b/Library/Homebrew/migrator.rb @@ -173,46 +173,50 @@ class Migrator end def migrate - if old_cellar.exist? && new_cellar.exist? + oh1 "Migrating #{Formatter.identifier(oldname)} to #{Formatter.identifier(newname)}" + lock + unlink_oldname + unlink_newname if new_cellar.exist? + repin + move_to_new_directory + link_oldname_cellar + link_oldname_opt + link_newname unless old_linked_keg.nil? + update_tabs + rescue Interrupt + ignore_interrupts { backup_oldname } + rescue Exception => e + onoe "Error occurred while migrating." + puts e + puts e.backtrace if ARGV.debug? + puts "Backing up..." + ignore_interrupts { backup_oldname } + ensure + unlock + end + + # move everything from Cellar/oldname to Cellar/newname + def move_to_new_directory + return unless old_cellar.exist? + + if new_cellar.exist? conflicted = false old_cellar.each_child do |c| - if (new_cellar/c.basename).exist? + next unless (new_cellar/c.basename).exist? + begin + FileUtils.rm_rf c + rescue Errno::EACCES conflicted = true onoe "#{new_cellar/c.basename} already exists." end end + if conflicted onoe "Remove #{new_cellar} manually and run brew migrate #{oldname}." return end end - begin - oh1 "Migrating #{Formatter.identifier(oldname)} to #{Formatter.identifier(newname)}" - lock - unlink_oldname - unlink_newname if new_cellar.exist? - move_to_new_directory - repin - link_oldname_cellar - link_oldname_opt - link_newname unless old_linked_keg.nil? - update_tabs - rescue Interrupt - ignore_interrupts { backup_oldname } - rescue Exception => e - onoe "Error occurred while migrating." - puts e - puts e.backtrace if ARGV.debug? - puts "Backuping..." - ignore_interrupts { backup_oldname } - ensure - unlock - end - end - - # move everything from Cellar/oldname to Cellar/newname - def move_to_new_directory puts "Moving to: #{new_cellar}" if new_cellar.exist? FileUtils.mv(old_cellar.children, new_cellar) |
