Use sudo for symlinks if necessary.
This commit is contained in:
parent
a1dd95d6ee
commit
2c71d9dcd8
@ -82,13 +82,7 @@ module Cask
|
|||||||
|
|
||||||
ohai "Moving #{self.class.english_name} '#{source.basename}' to '#{target}'"
|
ohai "Moving #{self.class.english_name} '#{source.basename}' to '#{target}'"
|
||||||
|
|
||||||
unless target.dirname.exist?
|
Utils.gain_permissions_mkpath(target.dirname, command: command) unless target.dirname.exist?
|
||||||
if target.dirname.ascend.find(&:directory?).writable?
|
|
||||||
target.dirname.mkpath
|
|
||||||
else
|
|
||||||
command.run!("/bin/mkdir", args: ["-p", target.dirname], sudo: true)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if target.directory?
|
if target.directory?
|
||||||
if target.writable?
|
if target.writable?
|
||||||
|
|||||||
@ -43,7 +43,7 @@ module Cask
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def link(force: false, **options)
|
def link(force: false, command: nil, **_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} " \
|
||||||
@ -57,26 +57,29 @@ module Cask
|
|||||||
if force && target.symlink? &&
|
if force && target.symlink? &&
|
||||||
(target.realpath == source.realpath || target.realpath.to_s.start_with?("#{cask.caskroom_path}/"))
|
(target.realpath == source.realpath || target.realpath.to_s.start_with?("#{cask.caskroom_path}/"))
|
||||||
opoo "#{message}; overwriting."
|
opoo "#{message}; overwriting."
|
||||||
target.delete
|
Utils.gain_permissions_remove(target, command: command)
|
||||||
else
|
else
|
||||||
raise CaskError, "#{message}."
|
raise CaskError, "#{message}."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ohai "Linking #{self.class.english_name} '#{source.basename}' to '#{target}'"
|
ohai "Linking #{self.class.english_name} '#{source.basename}' to '#{target}'"
|
||||||
create_filesystem_link(**options)
|
create_filesystem_link(command: command)
|
||||||
end
|
end
|
||||||
|
|
||||||
def unlink(**)
|
def unlink(command: nil, **)
|
||||||
return unless target.symlink?
|
return unless target.symlink?
|
||||||
|
|
||||||
ohai "Unlinking #{self.class.english_name} '#{target}'"
|
ohai "Unlinking #{self.class.english_name} '#{target}'"
|
||||||
target.delete
|
Utils.gain_permissions_remove(target, command: command)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_filesystem_link(command: nil, **_)
|
def create_filesystem_link(command: nil)
|
||||||
target.dirname.mkpath
|
Utils.gain_permissions_mkpath(target.dirname, command: command)
|
||||||
command.run!("/bin/ln", args: ["-h", "-f", "-s", "--", source, target])
|
|
||||||
|
command.run! "/bin/ln", args: ["-h", "-f", "-s", "--", source, target],
|
||||||
|
sudo: !target.dirname.writable?
|
||||||
|
|
||||||
add_altname_metadata(source, target.basename, command: command)
|
add_altname_metadata(source, target.basename, command: command)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -11,6 +11,17 @@ module Cask
|
|||||||
#
|
#
|
||||||
# @api private
|
# @api private
|
||||||
module Utils
|
module Utils
|
||||||
|
def self.gain_permissions_mkpath(path, command: SystemCommand)
|
||||||
|
dir = path.ascend.find(&:directory?)
|
||||||
|
return if path == dir
|
||||||
|
|
||||||
|
if dir.writable?
|
||||||
|
path.mkpath
|
||||||
|
else
|
||||||
|
command.run!("/bin/mkdir", args: ["-p", path], sudo: true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def self.gain_permissions_remove(path, command: SystemCommand)
|
def self.gain_permissions_remove(path, command: SystemCommand)
|
||||||
if path.respond_to?(:rmtree) && path.exist?
|
if path.respond_to?(:rmtree) && path.exist?
|
||||||
gain_permissions(path, ["-R"], command) do |p|
|
gain_permissions(path, ["-R"], command) do |p|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user