diff options
| author | Jack Nagel | 2014-03-27 18:39:54 -0500 |
|---|---|---|
| committer | Jack Nagel | 2014-03-27 18:42:19 -0500 |
| commit | f6cd59c448b914c14b5f41c536428d3c3c8da12c (patch) | |
| tree | 62720519e088fdfaf777d26af6a4658ee4de8060 | |
| parent | 212d5dab69b88ba06d51bc796e70bba2701eee57 (diff) | |
| download | homebrew-f6cd59c448b914c14b5f41c536428d3c3c8da12c.tar.bz2 | |
Return early so we can reduce nesting of conditionals
| -rw-r--r-- | Library/Homebrew/extend/pathname.rb | 84 |
1 files changed, 42 insertions, 42 deletions
diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index 4080ea581..fe8b2ce7f 100644 --- a/Library/Homebrew/extend/pathname.rb +++ b/Library/Homebrew/extend/pathname.rb @@ -291,49 +291,49 @@ class Pathname # perhaps confusingly, this Pathname object becomes the symlink pointing to # the src paramter. def make_relative_symlink src - self.dirname.mkpath - Dir.chdir self.dirname do + dirname.mkpath + + dirname.cd do # NOTE only system ln -s will create RELATIVE symlinks - quiet_system 'ln', '-s', src.relative_path_from(self.dirname), self.basename - if not $?.success? - if symlink? && exist? - raise <<-EOS.undent - Could not symlink file: #{src} - Target #{self} already exists as a symlink to #{readlink}. - If this file is from another formula, you may need to - `brew unlink` it. Otherwise, you may want to delete it. - To force the link and overwrite all other conflicting files, do: - brew link --overwrite formula_name - - To list all files that would be deleted: - brew link --overwrite --dry-run formula_name - EOS - elsif exist? - raise <<-EOS.undent - Could not symlink file: #{src} - Target #{self} already exists. You may need to delete it. - To force the link and overwrite all other conflicting files, do: - brew link --overwrite formula_name - - To list all files that would be deleted: - brew link --overwrite --dry-run formula_name - EOS - elsif symlink? - unlink - make_relative_symlink(src) - elsif !dirname.writable_real? - raise <<-EOS.undent - Could not symlink file: #{src} - #{dirname} is not writable. You should change its permissions. - EOS - else - raise <<-EOS.undent - Could not symlink file: #{src} - #{self} may already exist. - #{dirname} may not be writable. - EOS - end - end + return if quiet_system("ln", "-s", src.relative_path_from(dirname), basename) + end + + if symlink? && exist? + raise <<-EOS.undent + Could not symlink file: #{src} + Target #{self} already exists as a symlink to #{readlink}. + If this file is from another formula, you may need to + `brew unlink` it. Otherwise, you may want to delete it. + To force the link and overwrite all other conflicting files, do: + brew link --overwrite formula_name + + To list all files that would be deleted: + brew link --overwrite --dry-run formula_name + EOS + elsif exist? + raise <<-EOS.undent + Could not symlink file: #{src} + Target #{self} already exists. You may need to delete it. + To force the link and overwrite all other conflicting files, do: + brew link --overwrite formula_name + + To list all files that would be deleted: + brew link --overwrite --dry-run formula_name + EOS + elsif symlink? + unlink + make_relative_symlink(src) + elsif !dirname.writable_real? + raise <<-EOS.undent + Could not symlink file: #{src} + #{dirname} is not writable. You should change its permissions. + EOS + else + raise <<-EOS.undent + Could not symlink file: #{src} + #{self} may already exist. + #{dirname} may not be writable. + EOS end end |
