aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMarkus Reiter2017-04-02 17:58:45 +0200
committerGitHub2017-04-02 17:58:45 +0200
commita365e16b48c5ee3461fdda48d8aca58df954c4eb (patch)
treec9cb10a52b722e11348d276efffb30a4b1839fc2 /Library
parent081461a268f02aafa0753b6391e5129c929259c9 (diff)
parentc3baf55527daf8f739e67e682c144161868eff0c (diff)
downloadbrew-a365e16b48c5ee3461fdda48d8aca58df954c4eb.tar.bz2
Merge pull request #2431 from reitermarkus/fix-sudo-root-wheel
Use `sudo` if parent path of `target` is not writable.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/cask/lib/hbc/artifact/moved.rb18
-rw-r--r--Library/Homebrew/cask/lib/hbc/utils.rb10
2 files changed, 21 insertions, 7 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/artifact/moved.rb b/Library/Homebrew/cask/lib/hbc/artifact/moved.rb
index 01e98ac35..eaaa49e20 100644
--- a/Library/Homebrew/cask/lib/hbc/artifact/moved.rb
+++ b/Library/Homebrew/cask/lib/hbc/artifact/moved.rb
@@ -31,20 +31,26 @@ module Hbc
ohai "Moving #{self.class.artifact_english_name} '#{source.basename}' to '#{target}'."
target.dirname.mkpath
- FileUtils.move(source, target)
+
+ if target.parent.writable?
+ FileUtils.move(source, target)
+ else
+ SystemCommand.run("/bin/mv", args: [source, target], sudo: true)
+ end
+
add_altname_metadata target, source.basename.to_s
end
def delete
ohai "Removing #{self.class.artifact_english_name} '#{target}'."
- return unless Utils.path_occupied?(target)
-
raise CaskError, "Cannot remove undeletable #{self.class.artifact_english_name}." if MacOS.undeletable?(target)
- if force
- Utils.gain_permissions_remove(target, command: @command)
- else
+ return unless Utils.path_occupied?(target)
+
+ if target.parent.writable? && !force
target.rmtree
+ else
+ Utils.gain_permissions_remove(target, command: @command)
end
end
diff --git a/Library/Homebrew/cask/lib/hbc/utils.rb b/Library/Homebrew/cask/lib/hbc/utils.rb
index aba7138cb..ecb565e8e 100644
--- a/Library/Homebrew/cask/lib/hbc/utils.rb
+++ b/Library/Homebrew/cask/lib/hbc/utils.rb
@@ -38,7 +38,15 @@ module Hbc
module Utils
def self.gain_permissions_remove(path, command: SystemCommand)
if path.respond_to?(:rmtree) && path.exist?
- gain_permissions(path, ["-R"], command, &:rmtree)
+ gain_permissions(path, ["-R"], command) do |p|
+ if p.parent.writable?
+ p.rmtree
+ else
+ command.run("/bin/rm",
+ args: command_args + ["-r", "-f", "--", p],
+ sudo: true)
+ end
+ end
elsif File.symlink?(path)
gain_permissions(path, ["-h"], command, &FileUtils.method(:rm_f))
end