Class: Migrator Private
Overview
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
Helper class for migrating a formula from an old to a new name.
Defined Under Namespace
Classes: MigrationNeededError, MigratorDifferentTapsError, MigratorNoOldpathError
Instance Attribute Summary collapse
-
#formula ⇒ Formula
readonly
private
Instance of renamed formula.
-
#new_cellar ⇒ Pathname
readonly
private
Path to newname Cellar according to new name.
-
#new_cellar_existed ⇒ Boolean
readonly
private
True if new Cellar existed at initialization time.
-
#new_linked_keg_record ⇒ Pathname?
readonly
private
Path to newname keg that will be linked if old_linked_keg isn't nil.
-
#new_pin_record ⇒ Pathname
readonly
private
Path to newname pin.
-
#newname ⇒ String
readonly
private
New name of the formula.
-
#old_cellar ⇒ Pathname
readonly
private
Path to oldname's Cellar.
-
#old_full_linked_kegs ⇒ Array<Keg>
readonly
private
Oldname linked kegs that were fully linked.
-
#old_linked_kegs ⇒ Array<Keg>
readonly
private
Oldname linked kegs.
-
#old_opt_records ⇒ Array<Pathname>
readonly
private
Path to oldname opt.
-
#old_pin_link_record ⇒ Pathname?
readonly
private
Resolved path to oldname pin.
-
#old_pin_record ⇒ Pathname
readonly
private
Path to oldname pin.
-
#old_tabs ⇒ Array<Tab>
readonly
private
Tabs from oldname kegs.
-
#old_tap ⇒ Tap?
readonly
private
Tap of the old name.
-
#oldname ⇒ String
readonly
private
Old name of the formula.
Class Method Summary collapse
- .migrate_if_needed(formula, force:, dry_run: false) ⇒ void private
- .needs_migration?(formula) ⇒ Boolean private
- .oldnames_needing_migration(formula) ⇒ Array<String> private
Instance Method Summary collapse
- #backup_old_tabs ⇒ void private
-
#backup_oldname ⇒ void
private
Backup everything if errors occur while migrating.
- #backup_oldname_cellar ⇒ void private
-
#fix_tabs ⇒ void
private
Fix
INSTALL_RECEIPTs for tap-migrated formula. - #from_same_tap_user? ⇒ Boolean private
- #initialize(formula, oldname, force: false) ⇒ void constructor private
- #link_newname ⇒ Integer? private
-
#link_oldname_cellar ⇒ void
private
Remove
Cellar/oldnameif it exists. -
#link_oldname_opt ⇒ void
private
Link keg to opt if it was linked before migrating.
- #linked_old_linked_kegs ⇒ Array<Keg> private
- #lock ⇒ void private
- #merge_directory(directory) ⇒ void private
- #migrate ⇒ void private
-
#move_to_new_directory ⇒ void
private
Move everything from
Cellar/oldnametoCellar/newname. - #pinned? ⇒ Boolean private
- #remove_conflicts(directory) ⇒ Boolean private
- #repin ⇒ void private
- #unlink_newname ⇒ void private
- #unlink_oldname ⇒ void private
-
#unlink_oldname_cellar ⇒ void
private
Remove
Cellar/oldnamelink if it belongs to newname. -
#unlink_oldname_opt ⇒ void
private
Remove
opt/oldnamelink if it belongs to newname. - #unlock ⇒ void private
-
#update_tabs ⇒ void
private
After migration every
INSTALL_RECEIPT.jsonhas the wrong path to the formula so we must updateINSTALL_RECEIPTs.
Methods included from Utils::Output::Mixin
odebug, odeprecated, odie, odisabled, ofail, oh1, oh1_title, ohai, ohai_title, onoe, opoo, opoo_outside_github_actions, pretty_duration, pretty_installed, pretty_outdated, pretty_uninstalled
Methods included from Context
current, current=, #debug?, #quiet?, #verbose?, #with_context
Constructor Details
#initialize(formula, oldname, force: false) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'migrator.rb', line 148 def initialize(formula, oldname, force: false) @oldname = T.let(oldname, String) @newname = T.let(formula.name, String) @formula = T.let(formula, Formula) @old_cellar = T.let(HOMEBREW_CELLAR/oldname, Pathname) raise MigratorNoOldpathError, oldname unless old_cellar.exist? @old_tabs = T.let(old_cellar.subdirs.map { |d| Keg.new(d).tab }, T::Array[Tab]) first_tab = old_tabs.first @old_tap = T.let(first_tab&.tap, T.nilable(Tap)) raise MigratorDifferentTapsError.new(formula, oldname, old_tap) if !force && !from_same_tap_user? @new_cellar = T.let(HOMEBREW_CELLAR/formula.name, Pathname) @new_cellar_existed = T.let(@new_cellar.exist?, T::Boolean) @old_linked_kegs = T.let(linked_old_linked_kegs, T::Array[Keg]) @old_full_linked_kegs = T.let([], T::Array[Keg]) @old_opt_records = T.let([], T::Array[Pathname]) old_linked_kegs.each do |old_linked_keg| @old_full_linked_kegs << old_linked_keg if old_linked_keg.linked? @old_opt_records << old_linked_keg.opt_record if old_linked_keg.optlinked? end @new_linked_keg_record = T.let(nil, T.nilable(Pathname)) unless old_linked_kegs.empty? @new_linked_keg_record = HOMEBREW_CELLAR/"#{newname}/#{File.basename(old_linked_kegs.first.to_s)}" end @old_pin_record = T.let(HOMEBREW_PINNED_KEGS/oldname, Pathname) @new_pin_record = T.let(HOMEBREW_PINNED_KEGS/newname, Pathname) @pinned = T.let(old_pin_record.symlink?, T::Boolean) @old_pin_link_record = T.let(old_pin_record.symlink? ? old_pin_record.readlink : nil, T.nilable(Pathname)) end |
Instance Attribute Details
#formula ⇒ Formula (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Instance of renamed formula.
54 55 56 |
# File 'migrator.rb', line 54 def formula @formula end |
#new_cellar ⇒ Pathname (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Path to newname Cellar according to new name.
98 99 100 |
# File 'migrator.rb', line 98 def new_cellar @new_cellar end |
#new_cellar_existed ⇒ Boolean (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
True if new Cellar existed at initialization time.
102 103 104 |
# File 'migrator.rb', line 102 def new_cellar_existed @new_cellar_existed end |
#new_linked_keg_record ⇒ Pathname? (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Path to newname keg that will be linked if old_linked_keg isn't nil.
110 111 112 |
# File 'migrator.rb', line 110 def new_linked_keg_record @new_linked_keg_record end |
#new_pin_record ⇒ Pathname (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Path to newname pin.
106 107 108 |
# File 'migrator.rb', line 106 def new_pin_record @new_pin_record end |
#newname ⇒ String (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
New name of the formula.
94 95 96 |
# File 'migrator.rb', line 94 def newname @newname end |
#old_cellar ⇒ Pathname (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Path to oldname's Cellar.
62 63 64 |
# File 'migrator.rb', line 62 def old_cellar @old_cellar end |
#old_full_linked_kegs ⇒ Array<Keg> (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Oldname linked kegs that were fully linked.
78 79 80 |
# File 'migrator.rb', line 78 def old_full_linked_kegs @old_full_linked_kegs end |
#old_linked_kegs ⇒ Array<Keg> (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Oldname linked kegs.
74 75 76 |
# File 'migrator.rb', line 74 def old_linked_kegs @old_linked_kegs end |
#old_opt_records ⇒ Array<Pathname> (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Path to oldname opt.
70 71 72 |
# File 'migrator.rb', line 70 def old_opt_records @old_opt_records end |
#old_pin_link_record ⇒ Pathname? (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Resolved path to oldname pin.
90 91 92 |
# File 'migrator.rb', line 90 def old_pin_link_record @old_pin_link_record end |
#old_pin_record ⇒ Pathname (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Path to oldname pin.
66 67 68 |
# File 'migrator.rb', line 66 def old_pin_record @old_pin_record end |
#old_tabs ⇒ Array<Tab> (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Tabs from oldname kegs.
82 83 84 |
# File 'migrator.rb', line 82 def old_tabs @old_tabs end |
#old_tap ⇒ Tap? (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Tap of the old name.
86 87 88 |
# File 'migrator.rb', line 86 def old_tap @old_tap end |
#oldname ⇒ String (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Old name of the formula.
58 59 60 |
# File 'migrator.rb', line 58 def oldname @oldname end |
Class Method Details
.migrate_if_needed(formula, force:, dry_run: false) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'migrator.rb', line 129 def self.migrate_if_needed(formula, force:, dry_run: false) oldnames = Migrator.oldnames_needing_migration(formula) begin oldnames.each do |oldname| if dry_run oh1 "Would migrate formula #{Formatter.identifier(oldname)} to #{Formatter.identifier(formula.name)}" next end migrator = Migrator.new(formula, oldname, force:) migrator.migrate end rescue => e onoe e end end |
.needs_migration?(formula) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
124 125 126 |
# File 'migrator.rb', line 124 def self.needs_migration?(formula) !oldnames_needing_migration(formula).empty? end |
.oldnames_needing_migration(formula) ⇒ Array<String>
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
113 114 115 116 117 118 119 120 121 |
# File 'migrator.rb', line 113 def self.oldnames_needing_migration(formula) formula.oldnames.select do |oldname| oldname_rack = HOMEBREW_CELLAR/oldname next false if oldname_rack.symlink? next false unless oldname_rack.directory? true end end |
Instance Method Details
#backup_old_tabs ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
520 521 522 |
# File 'migrator.rb', line 520 def backup_old_tabs old_tabs.each(&:write) end |
#backup_oldname ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
Backup everything if errors occur while migrating.
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 |
# File 'migrator.rb', line 475 def backup_oldname unlink_oldname_opt unlink_oldname_cellar backup_oldname_cellar backup_old_tabs if pinned? && !old_pin_record.symlink? && (old_pin_link = old_pin_link_record) src_oldname = (old_pin_record.dirname/old_pin_link). old_pin_record.make_relative_symlink(src_oldname) new_pin_record.delete end if new_cellar.exist? new_cellar.subdirs.each do |d| newname_keg = Keg.new(d) newname_keg.unlink(verbose: verbose?) newname_keg.uninstall unless new_cellar_existed end end return if old_linked_kegs.empty? # The keg used to be linked and when we backup everything we restore # Cellar/oldname, the target also gets restored, so we are able to # create a keg using its old path old_full_linked_kegs.each do |old_linked_keg| old_linked_keg.link(verbose: verbose?) rescue Keg::LinkError old_linked_keg.unlink(verbose: verbose?) raise rescue Keg::AlreadyLinkedError old_linked_keg.unlink(verbose: verbose?) retry end (old_linked_kegs - old_full_linked_kegs).each do |old_linked_keg| old_linked_keg.optlink(verbose: verbose?) end end |
#backup_oldname_cellar ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
515 516 517 |
# File 'migrator.rb', line 515 def backup_oldname_cellar FileUtils.mv(new_cellar, old_cellar) unless old_cellar.exist? end |
#fix_tabs ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
Fix INSTALL_RECEIPTs for tap-migrated formula.
185 186 187 188 189 190 |
# File 'migrator.rb', line 185 def fix_tabs old_tabs.each do |tab| tab.tap = formula.tap tab.write end end |
#from_same_tap_user? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'migrator.rb', line 193 def from_same_tap_user? formula_tap_user = formula.tap&.user old_tap_user = nil new_tap = if (old_tap = self.old_tap) old_tap_user, = old_tap.user if (migrate_tap = old_tap.tap_migrations[oldname]) new_tap_user, new_tap_repo = migrate_tap.split("/") "#{new_tap_user}/#{new_tap_repo}" end end if formula_tap_user == old_tap_user true # Homebrew didn't use to update tabs while performing tap-migrations, # so there can be `INSTALL_RECEIPT`s containing wrong information about tap, # so we check if there is an entry about oldname migrated to tap and if # newname's tap is the same as tap to which oldname migrated, then we # can perform migrations and the taps for oldname and newname are the same. elsif formula.tap && old_tap && formula.tap == new_tap fix_tabs true else false end end |
#link_newname ⇒ Integer?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 |
# File 'migrator.rb', line 368 def link_newname new_linked_keg_record = self.new_linked_keg_record return unless new_linked_keg_record oh1 "Relinking #{Formatter.identifier(newname)}" new_keg = Keg.new(new_linked_keg_record) # If old_keg wasn't linked then we just optlink a keg. # If old keg wasn't optlinked and linked, we don't call this method at all. # If formula is keg-only we also optlink it. if formula.keg_only? || old_full_linked_kegs.empty? begin new_keg.optlink(verbose: verbose?) rescue Keg::LinkError => e onoe "Failed to create #{formula.opt_prefix}" raise end return end new_keg.remove_linked_keg_record if new_keg.linked? begin new_keg.link(overwrite: true, verbose: verbose?) rescue Keg::ConflictError => e onoe "The `brew link` step did not complete successfully." puts e puts puts "Possible conflicting files are:" new_keg.link(dry_run: true, overwrite: true, verbose: verbose?) raise rescue Keg::LinkError => e onoe "The `brew link` step did not complete successfully." puts e puts puts "You can try again using:" puts " brew link #{formula.name}" # Any exception means the `brew link` step did not complete. rescue Exception => e # rubocop:disable Lint/RescueException onoe "An unexpected error occurred during linking" puts e if debug? require "utils/backtrace" puts Utils::Backtrace.clean(e) end ignore_interrupts { new_keg.unlink(verbose: verbose?) } raise end end |
#link_oldname_cellar ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
Remove Cellar/oldname if it exists.
459 460 461 462 |
# File 'migrator.rb', line 459 def link_oldname_cellar old_cellar.delete if old_cellar.symlink? || old_cellar.exist? old_cellar.make_relative_symlink(formula.rack) end |
#link_oldname_opt ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
Link keg to opt if it was linked before migrating.
420 421 422 423 424 425 426 427 428 |
# File 'migrator.rb', line 420 def link_oldname_opt new_linked_keg_record = self.new_linked_keg_record return unless new_linked_keg_record old_opt_records.each do |old_opt_record| old_opt_record.delete if old_opt_record.symlink? old_opt_record.make_relative_symlink(new_linked_keg_record) end end |
#linked_old_linked_kegs ⇒ Array<Keg>
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
221 222 223 224 225 226 227 |
# File 'migrator.rb', line 221 def linked_old_linked_kegs keg_dirs = [] keg_dirs += new_cellar.subdirs if new_cellar.exist? keg_dirs += old_cellar.subdirs kegs = keg_dirs.map { |d| Keg.new(d) } kegs.select { |keg| keg.linked? || keg.optlinked? } end |
#lock ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
525 526 527 528 529 530 531 532 |
# File 'migrator.rb', line 525 def lock newname_lock = FormulaLock.new(newname) oldname_lock = FormulaLock.new(oldname) newname_lock.lock oldname_lock.lock @newname_lock = T.let(newname_lock, T.nilable(FormulaLock)) @oldname_lock = T.let(oldname_lock, T.nilable(FormulaLock)) end |
#merge_directory(directory) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
294 295 296 297 298 299 300 301 302 303 304 305 |
# File 'migrator.rb', line 294 def merge_directory(directory) directory.each_child do |c| new_path = new_cellar/c.relative_path_from(old_cellar) if c.directory? && !c.symlink? && new_path.exist? merge_directory(c) c.unlink else FileUtils.mv(c, new_path) end end end |
#migrate ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'migrator.rb', line 235 def migrate oh1 "Migrating formula #{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_kegs.empty? update_tabs return unless formula.outdated? opoo <<~EOS #{Formatter.identifier(newname)} is outdated! To avoid broken installations, as soon as possible please run: brew upgrade Or, if you're OK with a less reliable fix: brew upgrade #{newname} EOS rescue Interrupt ignore_interrupts { backup_oldname } # Any exception means the migration did not complete. rescue Exception => e # rubocop:disable Lint/RescueException onoe "The migration did not complete successfully." puts e if debug? require "utils/backtrace" puts Utils::Backtrace.clean(e) end puts "Backing up..." ignore_interrupts { backup_oldname } ensure unlock end |
#move_to_new_directory ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
Move everything from Cellar/oldname to Cellar/newname.
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
# File 'migrator.rb', line 309 def move_to_new_directory return unless old_cellar.exist? if new_cellar.exist? conflicted = remove_conflicts(old_cellar) odie "Remove #{new_cellar} and #{old_cellar} manually and run `brew reinstall #{newname}`." if conflicted end oh1 "Moving #{Formatter.identifier(oldname)} versions to #{new_cellar}" if new_cellar.exist? merge_directory(old_cellar) else FileUtils.mv(old_cellar, new_cellar) end end |
#pinned? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
230 231 232 |
# File 'migrator.rb', line 230 def pinned? @pinned end |
#remove_conflicts(directory) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'migrator.rb', line 272 def remove_conflicts(directory) conflicted = T.let(false, T::Boolean) directory.each_child do |c| if c.directory? && !c.symlink? conflicted ||= remove_conflicts(c) else next unless (new_cellar/c.relative_path_from(old_cellar)).exist? begin FileUtils.rm_rf c rescue Errno::EACCES conflicted = true onoe "#{new_cellar/c.basename} already exists." end end end conflicted end |
#repin ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
# File 'migrator.rb', line 326 def repin return unless pinned? old_pin_link_record = self.old_pin_link_record return unless old_pin_link_record # `old_pin_record` is a relative symlink and when we try to to read it # from <dir> we actually try to find file # <dir>/../<...>/../Cellar/name/version. # To repin formula we need to update the link thus that it points to # the right directory. # # NOTE: `old_pin_record.realpath.sub(oldname, newname)` is unacceptable # here, because it resolves every symlink for `old_pin_record` and then # substitutes oldname with newname. It breaks things like # `Pathname#make_relative_symlink`, where `Pathname#relative_path_from` # is used to find the relative path from source to destination parent # and it assumes no symlinks. src_oldname = (old_pin_record.dirname/old_pin_link_record). new_pin_record.make_relative_symlink(src_oldname.sub(oldname, newname)) old_pin_record.delete end |
#unlink_newname ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
359 360 361 362 363 364 365 |
# File 'migrator.rb', line 359 def unlink_newname oh1 "Temporarily unlinking #{Formatter.identifier(newname)}" new_cellar.subdirs.each do |d| keg = Keg.new(d) keg.unlink(verbose: verbose?) end end |
#unlink_oldname ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
350 351 352 353 354 355 356 |
# File 'migrator.rb', line 350 def unlink_oldname oh1 "Unlinking #{Formatter.identifier(oldname)}" old_cellar.subdirs.each do |d| keg = Keg.new(d) keg.unlink(verbose: verbose?) end end |
#unlink_oldname_cellar ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
Remove Cellar/oldname link if it belongs to newname.
466 467 468 469 470 471 |
# File 'migrator.rb', line 466 def unlink_oldname_cellar if (old_cellar.symlink? && !old_cellar.exist?) || (old_cellar.symlink? && formula.rack.exist? && formula.rack.realpath == old_cellar.realpath) old_cellar.unlink end end |
#unlink_oldname_opt ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
Remove opt/oldname link if it belongs to newname.
443 444 445 446 447 448 449 450 451 452 453 454 455 |
# File 'migrator.rb', line 443 def unlink_oldname_opt new_linked_keg_record = self.new_linked_keg_record return unless new_linked_keg_record&.exist? old_opt_records.each do |old_opt_record| next unless old_opt_record.symlink? next unless old_opt_record.exist? next if new_linked_keg_record.realpath != old_opt_record.realpath old_opt_record.unlink old_opt_record.parent.rmdir_if_possible end end |
#unlock ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
535 536 537 538 |
# File 'migrator.rb', line 535 def unlock @newname_lock&.unlock @oldname_lock&.unlock end |
#update_tabs ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
After migration every INSTALL_RECEIPT.json has the wrong path to the formula
so we must update INSTALL_RECEIPTs.
433 434 435 436 437 438 439 |
# File 'migrator.rb', line 433 def update_tabs new_tabs = new_cellar.subdirs.map { |d| Keg.new(d).tab } new_tabs.each do |tab| tab.source["path"] = formula.path.to_s if tab.source["path"] tab.write end end |