aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/cask/lib/hbc/caskroom.rb27
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli.rb1
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/reinstall.rb49
-rw-r--r--Library/Homebrew/cask/test/cask/cli/reinstall_test.rb27
-rw-r--r--Library/Homebrew/manpages/brew-cask.1.md3
5 files changed, 88 insertions, 19 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/caskroom.rb b/Library/Homebrew/cask/lib/hbc/caskroom.rb
index 583cac34a..7bc8294e1 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."
- system "/usr/bin/sudo", "--", "/bin/mv", "--", repo_caskroom.to_s, Hbc.caskroom.parent.to_s
+ SystemCommand.run("/bin/mv", args: [repo_caskroom, Hbc.caskroom.parent], sudo: true)
end
end
@@ -21,24 +21,13 @@ module Hbc
return if Hbc.caskroom.exist?
ohai "Creating Caskroom at #{Hbc.caskroom}"
- if Hbc.caskroom.parent.writable?
- Hbc.caskroom.mkpath
- else
- ohai "We'll set permissions properly so we won't need sudo in the future"
- toplevel_dir = Hbc.caskroom
- toplevel_dir = toplevel_dir.parent until toplevel_dir.parent.root?
- unless toplevel_dir.directory?
- # If a toplevel dir such as '/opt' must be created, enforce standard permissions.
- # sudo in system is rude.
- system "/usr/bin/sudo", "--", "/bin/mkdir", "--", toplevel_dir
- system "/usr/bin/sudo", "--", "/bin/chmod", "--", "0775", toplevel_dir
- end
- # sudo in system is rude.
- system "/usr/bin/sudo", "--", "/bin/mkdir", "-p", "--", Hbc.caskroom
- unless Hbc.caskroom.parent == toplevel_dir
- system "/usr/bin/sudo", "--", "/usr/sbin/chown", "-R", "--", "#{Utils.current_user}:staff", Hbc.caskroom.parent.to_s
- end
- end
+ ohai "We'll set permissions properly so we won't need sudo in the future"
+ sudo = !Hbc.caskroom.parent.writable?
+
+ SystemCommand.run("/bin/mkdir", args: ["-p", Hbc.caskroom], sudo: sudo)
+ SystemCommand.run("/bin/chmod", args: ["g+rwx", Hbc.caskroom], sudo: sudo)
+ SystemCommand.run("/usr/sbin/chown", args: [Utils.current_user, Hbc.caskroom], sudo: sudo)
+ SystemCommand.run("/usr/bin/chgrp", args: ["admin", Hbc.caskroom], sudo: sudo)
end
end
end
diff --git a/Library/Homebrew/cask/lib/hbc/cli.rb b/Library/Homebrew/cask/lib/hbc/cli.rb
index d062c6a7d..c9625c7e2 100644
--- a/Library/Homebrew/cask/lib/hbc/cli.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli.rb
@@ -15,6 +15,7 @@ require "hbc/cli/home"
require "hbc/cli/info"
require "hbc/cli/install"
require "hbc/cli/list"
+require "hbc/cli/reinstall"
require "hbc/cli/search"
require "hbc/cli/style"
require "hbc/cli/uninstall"
diff --git a/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb b/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb
new file mode 100644
index 000000000..ac514bd50
--- /dev/null
+++ b/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb
@@ -0,0 +1,49 @@
+module Hbc
+ class CLI
+ class Reinstall < Install
+ def self.install_casks(cask_tokens, force, skip_cask_deps, require_sha)
+ count = 0
+ cask_tokens.each do |cask_token|
+ begin
+ cask = Hbc.load(cask_token)
+
+ if cask.installed?
+ # use copy of cask for uninstallation to avoid 'No such file or directory' bug
+ installed_cask = cask
+ latest_installed_version = installed_cask.timestamped_versions.last
+
+ unless latest_installed_version.nil?
+ latest_installed_cask_file = installed_cask.metadata_master_container_path
+ .join(latest_installed_version
+ .join(File::Separator),
+ "Casks", "#{cask_token}.rb")
+
+ # use the same cask file that was used for installation, if possible
+ installed_cask = Hbc.load(latest_installed_cask_file) if latest_installed_cask_file.exist?
+ end
+
+ # Always force uninstallation, ignore method parameter
+ Installer.new(installed_cask, force: true).uninstall
+ end
+
+ Installer.new(cask,
+ force: force,
+ skip_cask_deps: skip_cask_deps,
+ require_sha: require_sha).install
+ count += 1
+ rescue CaskUnavailableError => e
+ warn_unavailable_with_suggestion cask_token, e
+ rescue CaskNoShasumError => e
+ opoo e.message
+ count += 1
+ end
+ end
+ count.zero? ? nil : count == cask_tokens.length
+ end
+
+ def self.help
+ "reinstalls the given Cask"
+ end
+ end
+ end
+end
diff --git a/Library/Homebrew/cask/test/cask/cli/reinstall_test.rb b/Library/Homebrew/cask/test/cask/cli/reinstall_test.rb
new file mode 100644
index 000000000..22f0d23fd
--- /dev/null
+++ b/Library/Homebrew/cask/test/cask/cli/reinstall_test.rb
@@ -0,0 +1,27 @@
+require "test_helper"
+
+describe Hbc::CLI::Reinstall do
+ it "allows reinstalling a Cask" do
+ shutup do
+ Hbc::CLI::Install.run("local-transmission")
+ end
+ Hbc.load("local-transmission").must_be :installed?
+
+ shutup do
+ Hbc::CLI::Reinstall.run("local-transmission")
+ end
+ Hbc.load("local-transmission").must_be :installed?
+ end
+
+ it "allows reinstalling a non installed Cask" do
+ shutup do
+ Hbc::CLI::Uninstall.run("local-transmission")
+ end
+ Hbc.load("local-transmission").wont_be :installed?
+
+ shutup do
+ Hbc::CLI::Reinstall.run("local-transmission")
+ end
+ Hbc.load("local-transmission").must_be :installed?
+ end
+end
diff --git a/Library/Homebrew/manpages/brew-cask.1.md b/Library/Homebrew/manpages/brew-cask.1.md
index 92c58ba29..feab9f76e 100644
--- a/Library/Homebrew/manpages/brew-cask.1.md
+++ b/Library/Homebrew/manpages/brew-cask.1.md
@@ -86,6 +86,9 @@ names, and other aspects of this manual are still subject to change.
If <token> is given, summarize the staged files associated with the
given Cask.
+ * `reinstall` <token> [ <token> ...]
+ Reinstall the given Cask.
+
* `search` or `-S` [<text> | /<regexp>/]:
Without argument, display all Casks available for install, otherwise
perform a substring search of known Cask tokens for <text> or, if the