diff options
| author | Markus Reiter | 2016-09-23 22:02:23 +0200 |
|---|---|---|
| committer | Markus Reiter | 2016-09-24 12:24:35 +0200 |
| commit | 58e36c73193befb57d351344cea2a4a33fef850d (patch) | |
| tree | 3d26751835440341e5a42a189cf580e6253785df /Library/Homebrew/migrator.rb | |
| parent | bbc3f1c3a852e6cfd26a7a7c333092fae0520eb4 (diff) | |
| download | brew-58e36c73193befb57d351344cea2a4a33fef850d.tar.bz2 | |
Fix Style/GuardClause.
Diffstat (limited to 'Library/Homebrew/migrator.rb')
| -rw-r--r-- | Library/Homebrew/migrator.rb | 69 |
1 files changed, 33 insertions, 36 deletions
diff --git a/Library/Homebrew/migrator.rb b/Library/Homebrew/migrator.rb index d8c06de1a..addd97c8a 100644 --- a/Library/Homebrew/migrator.rb +++ b/Library/Homebrew/migrator.rb @@ -182,22 +182,21 @@ class Migrator end def repin - if pinned? - # 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 relative path from source to destination parent and - # it assumes no symlinks. - src_oldname = old_pin_record.dirname.join(old_pin_link_record).expand_path - new_pin_record.make_relative_symlink(src_oldname.sub(oldname, newname)) - old_pin_record.delete - end + return unless pinned? + # 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 relative path from source to destination parent and + # it assumes no symlinks. + src_oldname = old_pin_record.dirname.join(old_pin_link_record).expand_path + new_pin_record.make_relative_symlink(src_oldname.sub(oldname, newname)) + old_pin_record.delete end def unlink_oldname @@ -254,10 +253,9 @@ class Migrator # Link keg to opt if it was linked before migrating. def link_oldname_opt - if old_opt_record - old_opt_record.delete if old_opt_record.symlink? - old_opt_record.make_relative_symlink(new_linked_keg_record) - end + return unless old_opt_record + old_opt_record.delete if old_opt_record.symlink? + old_opt_record.make_relative_symlink(new_linked_keg_record) end # After migtaion every INSTALL_RECEIPT.json has wrong path to the formula @@ -316,23 +314,22 @@ class Migrator end end - unless old_linked_keg.nil? - # 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 - old_linked_keg.link - rescue Keg::LinkError - old_linked_keg.unlink - raise - rescue Keg::AlreadyLinkedError - old_linked_keg.unlink - retry - end - else - old_linked_keg.optlink + return if old_linked_keg.nil? + # 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 + old_linked_keg.link + rescue Keg::LinkError + old_linked_keg.unlink + raise + rescue Keg::AlreadyLinkedError + old_linked_keg.unlink + retry end + else + old_linked_keg.optlink end end |
