Skip to content

Commit

Permalink
Use sudo for symlinks if necessary.
Browse files Browse the repository at this point in the history
  • Loading branch information
reitermarkus committed May 13, 2023
1 parent 8ea287c commit 8f06d32
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions Library/Homebrew/cask/artifact/symlinked.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def summarize_installed

private

def link(force: false, **options)
def link(force: false, command: nil, **options)
unless source.exist?
raise CaskError,
"It seems the #{self.class.link_type_english_name.downcase} " \
Expand All @@ -64,19 +64,20 @@ def link(force: false, **options)
end

ohai "Linking #{self.class.english_name} '#{source.basename}' to '#{target}'"
create_filesystem_link(**options)
create_filesystem_link(command: command)
end

def unlink(**)
return unless target.symlink?

ohai "Unlinking #{self.class.english_name} '#{target}'"
target.delete
Utils.gain_permissions_remove(target, command: command)
end

def create_filesystem_link(command: nil, **_)
def create_filesystem_link(command: nil)
target.dirname.mkpath
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)
end
end
Expand Down

0 comments on commit 8f06d32

Please sign in to comment.