Merge pull request #8537 from miccal/cask_symlink

cask/artifact/symlinked: allow --force to overwrite symbolic links
This commit is contained in:
Markus Reiter 2020-09-03 07:55:44 +02:00 committed by GitHub
commit 233cac0d95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -40,7 +40,7 @@ module Cask
private
def link(**options)
def link(force: false, **options)
unless source.exist?
raise CaskError,
"It seems the #{self.class.link_type_english_name.downcase} " \
@ -48,9 +48,16 @@ module Cask
end
if target.exist?
raise CaskError,
"It seems there already exists #{self.class.english_article} " \
"#{self.class.english_name} at '#{target}'; not overwriting."
message = "It seems there is already #{self.class.english_article} " \
"#{self.class.english_name} at '#{target}'"
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
ohai "Linking #{self.class.english_name} '#{source.basename}' to '#{target}'."