diff options
| author | Yoshimasa Niwa | 2016-10-10 11:11:52 -0700 |
|---|---|---|
| committer | Yoshimasa Niwa | 2016-10-10 11:17:07 -0700 |
| commit | d51cd15e0c748d1b2a35f6327a131622b6ee48b7 (patch) | |
| tree | 486307d0df7f193d9c66cd6e8c88af27437db3cd /Library | |
| parent | d00f35b8c4dcdcbf86074015f0471f27e3dc2aaa (diff) | |
| download | brew-d51cd15e0c748d1b2a35f6327a131622b6ee48b7.tar.bz2 | |
Create caskroom without sudo in writable parent.
In case the parent directory of Caskroom is writable for the user, we
don't need to use `sudo` to execute commands.
Make a generic method to run commands that has an option to switch sudo
so that we can run commands with and without sudo.
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/caskroom.rb | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/caskroom.rb b/Library/Homebrew/cask/lib/hbc/caskroom.rb index 6375345ee..a8af58001 100644 --- a/Library/Homebrew/cask/lib/hbc/caskroom.rb +++ b/Library/Homebrew/cask/lib/hbc/caskroom.rb @@ -13,7 +13,7 @@ module Hbc FileUtils.mv repo_caskroom, Hbc.caskroom else opoo "#{Hbc.caskroom.parent} is not writable, sudo is needed to move the Caskroom." - sudo "/bin/mv", repo_caskroom.to_s, Hbc.caskroom.parent.to_s + command "/bin/mv", repo_caskroom, Hbc.caskroom.parent, :use_sudo => true end end @@ -22,16 +22,23 @@ module Hbc ohai "Creating Caskroom at #{Hbc.caskroom}" ohai "We'll set permissions properly so we won't need sudo in the future" + use_sudo = !Hbc.caskroom.parent.writable? - sudo "/bin/mkdir", "-p", Hbc.caskroom - sudo "/bin/chmod", "g+rwx", Hbc.caskroom - sudo "/usr/sbin/chown", Utils.current_user, Hbc.caskroom - sudo "/usr/bin/chgrp", "admin", Hbc.caskroom + command "/bin/mkdir", "-p", Hbc.caskroom, :use_sudo => use_sudo + command "/bin/chmod", "g+rwx", Hbc.caskroom, :use_sudo => use_sudo + command "/usr/sbin/chown", Utils.current_user, Hbc.caskroom, :use_sudo => use_sudo + command "/usr/bin/chgrp", "admin", Hbc.caskroom, :use_sudo => use_sudo end - def sudo(*args) - ohai "/usr/bin/sudo #{args.join(" ")}" - system "/usr/bin/sudo", *args + def command(*args) + options = args.last.is_a?(Hash) ? args.pop : {} + + if options[:use_sudo] + args.unshift "/usr/bin/sudo" + end + + ohai args.join(" ") + system *args end end end |
