From 1606e5db6fa91fae8eb32d876e100f3835ec099a Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Wed, 29 Mar 2017 11:21:31 +0100 Subject: [PATCH] migrator: move around some migration logic. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- Library/Homebrew/migrator.rb | 60 +++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/Library/Homebrew/migrator.rb b/Library/Homebrew/migrator.rb index 44614d553e..96121ee328 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)