Rework make_relative_symlink error handling and move it into keg
This commit is contained in:
parent
9d72555644
commit
d3ab439b7c
@ -290,53 +290,9 @@ class Pathname
|
|||||||
(dirname+link).exist?
|
(dirname+link).exist?
|
||||||
end
|
end
|
||||||
|
|
||||||
# perhaps confusingly, this Pathname object becomes the symlink pointing to
|
def make_relative_symlink(src)
|
||||||
# the src paramter.
|
|
||||||
def make_relative_symlink src
|
|
||||||
dirname.mkpath
|
dirname.mkpath
|
||||||
|
File.symlink(src.relative_path_from(dirname), self)
|
||||||
dirname.cd do
|
|
||||||
# NOTE only system ln -s will create RELATIVE symlinks
|
|
||||||
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
|
end
|
||||||
|
|
||||||
def / that
|
def / that
|
||||||
@ -503,6 +459,7 @@ module ObserverPathnameExtension
|
|||||||
end
|
end
|
||||||
def make_relative_symlink src
|
def make_relative_symlink src
|
||||||
super
|
super
|
||||||
|
puts "ln -s #{src.relative_path_from(dirname)} #{basename}" if ARGV.verbose?
|
||||||
ObserverPathnameExtension.n += 1
|
ObserverPathnameExtension.n += 1
|
||||||
end
|
end
|
||||||
def install_info
|
def install_info
|
||||||
|
|||||||
@ -183,7 +183,7 @@ class Keg < Pathname
|
|||||||
end
|
end
|
||||||
|
|
||||||
unless mode.dry_run
|
unless mode.dry_run
|
||||||
linked_keg_record.make_relative_symlink(self)
|
make_relative_symlink(linked_keg_record, self, mode)
|
||||||
optlink
|
optlink
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -203,7 +203,7 @@ class Keg < Pathname
|
|||||||
elsif from.exist?
|
elsif from.exist?
|
||||||
from.delete
|
from.delete
|
||||||
end
|
end
|
||||||
from.make_relative_symlink(self)
|
make_relative_symlink(from, self)
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete_pyc_files!
|
def delete_pyc_files!
|
||||||
@ -250,7 +250,45 @@ class Keg < Pathname
|
|||||||
end
|
end
|
||||||
|
|
||||||
dst.delete if mode.overwrite && (dst.exist? || dst.symlink?)
|
dst.delete if mode.overwrite && (dst.exist? || dst.symlink?)
|
||||||
dst.make_relative_symlink src
|
dst.make_relative_symlink(src)
|
||||||
|
rescue Errno::EEXIST
|
||||||
|
if dst.symlink? && dst.exist?
|
||||||
|
raise <<-EOS.undent
|
||||||
|
Could not symlink file: #{src}
|
||||||
|
Target #{dst} already exists as a symlink to #{dst.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 dst.exist?
|
||||||
|
raise <<-EOS.undent
|
||||||
|
Could not symlink file: #{src}
|
||||||
|
Target #{dst} 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 dst.symlink?
|
||||||
|
dst.unlink
|
||||||
|
retry
|
||||||
|
end
|
||||||
|
rescue Errno::EACCES
|
||||||
|
raise <<-EOS.undent
|
||||||
|
Could not symlink file: #{src}
|
||||||
|
#{dst.dirname} is not writable. You should change its permissions.
|
||||||
|
EOS
|
||||||
|
rescue SystemCallError
|
||||||
|
raise <<-EOS.undent
|
||||||
|
Could not symlink file: #{src}
|
||||||
|
#{dst} may already exist.
|
||||||
|
#{dst.dirname} may not be writable.
|
||||||
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
# symlinks the contents of self+foo recursively into #{HOMEBREW_PREFIX}/foo
|
# symlinks the contents of self+foo recursively into #{HOMEBREW_PREFIX}/foo
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user