migrator: allow new cellar to exist already
Lets us migrate a formula to a name that may have previously been used. If gnupg 1.x is installed as "gnupg" and gnupg 2.x is installed as "gnupg2," it's currently not possible to rename gnupg2 -> gnupg, since the 1.4 keg will already be installed in the "gnupg" Cellar, so in order to reclaim the name "gnupg" to be used for 2.1, either 1.x must be manually uninstalled, or the new cellar needs to be allowed to exist already.
This commit is contained in:
		
							parent
							
								
									f8cf506670
								
							
						
					
					
						commit
						845d083464
					
				@ -147,15 +147,25 @@ class Migrator
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def migrate
 | 
			
		||||
    if new_cellar.exist?
 | 
			
		||||
      onoe "#{new_cellar} already exists; remove it manually and run brew migrate #{oldname}."
 | 
			
		||||
      return
 | 
			
		||||
    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
 | 
			
		||||
      link_oldname_cellar
 | 
			
		||||
@ -178,7 +188,11 @@ class Migrator
 | 
			
		||||
  # move everything from Cellar/oldname to Cellar/newname
 | 
			
		||||
  def move_to_new_directory
 | 
			
		||||
    puts "Moving to: #{new_cellar}"
 | 
			
		||||
    FileUtils.mv(old_cellar, new_cellar)
 | 
			
		||||
    if new_cellar.exist?
 | 
			
		||||
      FileUtils.mv(old_cellar.children, new_cellar)
 | 
			
		||||
    else
 | 
			
		||||
      FileUtils.mv(old_cellar, new_cellar)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def repin
 | 
			
		||||
@ -207,6 +221,14 @@ class Migrator
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def unlink_newname
 | 
			
		||||
    oh1 "Unlinking #{Formatter.identifier(newname)}"
 | 
			
		||||
    new_cellar.subdirs.each do |d|
 | 
			
		||||
      keg = Keg.new(d)
 | 
			
		||||
      keg.unlink
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def link_newname
 | 
			
		||||
    oh1 "Linking #{Formatter.identifier(newname)}"
 | 
			
		||||
    new_keg = Keg.new(new_linked_keg_record)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user