Merge pull request #8537 from miccal/cask_symlink
cask/artifact/symlinked: allow --force to overwrite symbolic links
This commit is contained in:
commit
233cac0d95
@ -40,7 +40,7 @@ module Cask
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def link(**options)
|
def link(force: false, **options)
|
||||||
unless source.exist?
|
unless source.exist?
|
||||||
raise CaskError,
|
raise CaskError,
|
||||||
"It seems the #{self.class.link_type_english_name.downcase} " \
|
"It seems the #{self.class.link_type_english_name.downcase} " \
|
||||||
@ -48,9 +48,16 @@ module Cask
|
|||||||
end
|
end
|
||||||
|
|
||||||
if target.exist?
|
if target.exist?
|
||||||
raise CaskError,
|
message = "It seems there is already #{self.class.english_article} " \
|
||||||
"It seems there already exists #{self.class.english_article} " \
|
"#{self.class.english_name} at '#{target}'"
|
||||||
"#{self.class.english_name} at '#{target}'; not overwriting."
|
|
||||||
|
if force && target.symlink? && \
|
||||||
|
(target.realpath == source.realpath || target.realpath.to_s.start_with?("#{cask.caskroom_path}/"))
|
||||||
|
opoo "#{message}; overwriting."
|
||||||
|
target.delete
|
||||||
|
else
|
||||||
|
raise CaskError, "#{message}."
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ohai "Linking #{self.class.english_name} '#{source.basename}' to '#{target}'."
|
ohai "Linking #{self.class.english_name} '#{source.basename}' to '#{target}'."
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user