Return early so we can reduce nesting of conditionals
This commit is contained in:
parent
ed0be26c77
commit
4e918666d7
@ -291,49 +291,49 @@ class Pathname
|
|||||||
# perhaps confusingly, this Pathname object becomes the symlink pointing to
|
# perhaps confusingly, this Pathname object becomes the symlink pointing to
|
||||||
# the src paramter.
|
# the src paramter.
|
||||||
def make_relative_symlink src
|
def make_relative_symlink src
|
||||||
self.dirname.mkpath
|
dirname.mkpath
|
||||||
Dir.chdir self.dirname do
|
|
||||||
|
dirname.cd do
|
||||||
# NOTE only system ln -s will create RELATIVE symlinks
|
# NOTE only system ln -s will create RELATIVE symlinks
|
||||||
quiet_system 'ln', '-s', src.relative_path_from(self.dirname), self.basename
|
return if quiet_system("ln", "-s", src.relative_path_from(dirname), basename)
|
||||||
if not $?.success?
|
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:
|
if symlink? && exist?
|
||||||
brew link --overwrite --dry-run formula_name
|
raise <<-EOS.undent
|
||||||
EOS
|
Could not symlink file: #{src}
|
||||||
elsif exist?
|
Target #{self} already exists as a symlink to #{readlink}.
|
||||||
raise <<-EOS.undent
|
If this file is from another formula, you may need to
|
||||||
Could not symlink file: #{src}
|
`brew unlink` it. Otherwise, you may want to delete it.
|
||||||
Target #{self} already exists. You may need to delete it.
|
To force the link and overwrite all other conflicting files, do:
|
||||||
To force the link and overwrite all other conflicting files, do:
|
brew link --overwrite formula_name
|
||||||
brew link --overwrite formula_name
|
|
||||||
|
|
||||||
To list all files that would be deleted:
|
To list all files that would be deleted:
|
||||||
brew link --overwrite --dry-run formula_name
|
brew link --overwrite --dry-run formula_name
|
||||||
EOS
|
EOS
|
||||||
elsif symlink?
|
elsif exist?
|
||||||
unlink
|
raise <<-EOS.undent
|
||||||
make_relative_symlink(src)
|
Could not symlink file: #{src}
|
||||||
elsif !dirname.writable_real?
|
Target #{self} already exists. You may need to delete it.
|
||||||
raise <<-EOS.undent
|
To force the link and overwrite all other conflicting files, do:
|
||||||
Could not symlink file: #{src}
|
brew link --overwrite formula_name
|
||||||
#{dirname} is not writable. You should change its permissions.
|
|
||||||
EOS
|
To list all files that would be deleted:
|
||||||
else
|
brew link --overwrite --dry-run formula_name
|
||||||
raise <<-EOS.undent
|
EOS
|
||||||
Could not symlink file: #{src}
|
elsif symlink?
|
||||||
#{self} may already exist.
|
unlink
|
||||||
#{dirname} may not be writable.
|
make_relative_symlink(src)
|
||||||
EOS
|
elsif !dirname.writable_real?
|
||||||
end
|
raise <<-EOS.undent
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user