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.
This commit is contained in:
		
							parent
							
								
									5d1f4dd531
								
							
						
					
					
						commit
						1606e5db6f
					
				@ -173,27 +173,12 @@ class Migrator
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def migrate
 | 
			
		||||
    if old_cellar.exist? && new_cellar.exist?
 | 
			
		||||
      conflicted = false
 | 
			
		||||
      old_cellar.each_child do |c|
 | 
			
		||||
        if (new_cellar/c.basename).exist?
 | 
			
		||||
          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
 | 
			
		||||
    move_to_new_directory
 | 
			
		||||
    link_oldname_cellar
 | 
			
		||||
    link_oldname_opt
 | 
			
		||||
    link_newname unless old_linked_keg.nil?
 | 
			
		||||
@ -204,15 +189,34 @@ class Migrator
 | 
			
		||||
    onoe "Error occurred while migrating."
 | 
			
		||||
    puts e
 | 
			
		||||
    puts e.backtrace if ARGV.debug?
 | 
			
		||||
      puts "Backuping..."
 | 
			
		||||
    puts "Backing up..."
 | 
			
		||||
    ignore_interrupts { backup_oldname }
 | 
			
		||||
  ensure
 | 
			
		||||
    unlock
 | 
			
		||||
  end
 | 
			
		||||
  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|
 | 
			
		||||
        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
 | 
			
		||||
 | 
			
		||||
    puts "Moving to: #{new_cellar}"
 | 
			
		||||
    if new_cellar.exist?
 | 
			
		||||
      FileUtils.mv(old_cellar.children, new_cellar)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user