aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/migrator.rb
diff options
context:
space:
mode:
authorVlad Shablinsky2015-08-12 16:21:13 +0300
committerXu Cheng2015-08-15 20:16:31 +0800
commit9736159c0366b760564bab0fcf0d6ba1ad7f832e (patch)
tree5b2c7492da484ffd148cf079b5cef373f32a31b0 /Library/Homebrew/migrator.rb
parent2c1d8bcf6582ec7efc9870f9d4e4e9275804ac7e (diff)
downloadbrew-9736159c0366b760564bab0fcf0d6ba1ad7f832e.tar.bz2
migrator: don't link newname if oldname isn't linked
- link newname only if oldname used to be linked - optlink newname only if oldname used to be optlinked.
Diffstat (limited to 'Library/Homebrew/migrator.rb')
-rw-r--r--Library/Homebrew/migrator.rb42
1 files changed, 27 insertions, 15 deletions
diff --git a/Library/Homebrew/migrator.rb b/Library/Homebrew/migrator.rb
index 8e86d0853..7c9821d54 100644
--- a/Library/Homebrew/migrator.rb
+++ b/Library/Homebrew/migrator.rb
@@ -131,7 +131,7 @@ class Migrator
unlink_oldname
move_to_new_directory
repin
- link_newname
+ link_newname if oldkeg_linked?
link_oldname_opt
link_oldname_cellar
update_tabs
@@ -182,7 +182,10 @@ class Migrator
oh1 "Linking #{Tty.green}#{newname}#{Tty.reset}"
keg = Keg.new(formula.installed_prefix)
- if formula.keg_only?
+ # 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_linked_keg_record
begin
keg.optlink
rescue Keg::LinkError => e
@@ -241,7 +244,7 @@ class Migrator
# Remove opt/oldname link if it belongs to newname.
def unlink_oldname_opt
return unless old_opt_record
- if (old_opt_record.symlink? && old_opt_record.exist?) \
+ if old_opt_record.symlink? && old_opt_record.exist? \
&& formula.installed_prefix.exist? \
&& formula.installed_prefix.realpath == old_opt_record.realpath
old_opt_record.unlink
@@ -285,18 +288,27 @@ class Migrator
end
if oldkeg_linked?
- begin
- # 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
- keg = Keg.new(Pathname.new(oldkeg.to_s))
- keg.link
- rescue Keg::LinkError
- keg.unlink
- raise
- rescue Keg::AlreadyLinkedError
- keg.unlink
- retry
+ # 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
+ if old_linked_keg_record
+ begin
+ oldkeg.link
+ rescue Keg::LinkError
+ oldkeg.unlink
+ raise
+ rescue Keg::AlreadyLinkedError
+ oldkeg.unlink
+ retry
+ end
+ else
+ begin
+ oldkeg.optlink
+ rescue Keg::LinkError => e
+ onoe "Failed to create #{formula.opt_prefix}"
+ puts e
+ raise
+ end
end
end
end