Skip to content
Snippets Groups Projects
Commit 1606e5db authored by Mike McQuaid's avatar Mike McQuaid
Browse files

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.
parent 5d1f4dd5
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment