diff options
Diffstat (limited to 'Library/Homebrew/cask/lib/hbc')
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/artifact/moved.rb | 18 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/container.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/container/executable.rb | 18 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/utils.rb | 19 |
4 files changed, 43 insertions, 14 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/container.rb b/Library/Homebrew/cask/lib/hbc/container.rb index fc7246f3d..c6b2c3c37 100644 --- a/Library/Homebrew/cask/lib/hbc/container.rb +++ b/Library/Homebrew/cask/lib/hbc/container.rb @@ -4,6 +4,7 @@ require "hbc/container/bzip2" require "hbc/container/cab" require "hbc/container/criteria" require "hbc/container/dmg" +require "hbc/container/executable" require "hbc/container/generic_unar" require "hbc/container/gzip" require "hbc/container/lzma" @@ -39,6 +40,7 @@ module Hbc Gzip, # pure gzip Lzma, # pure lzma Xz, # pure xz + Executable, ] # for explicit use only (never autodetected): # Hbc::Container::Naked diff --git a/Library/Homebrew/cask/lib/hbc/container/executable.rb b/Library/Homebrew/cask/lib/hbc/container/executable.rb new file mode 100644 index 000000000..848f6d4be --- /dev/null +++ b/Library/Homebrew/cask/lib/hbc/container/executable.rb @@ -0,0 +1,18 @@ +require "hbc/container/naked" +require "vendor/macho/macho" + +module Hbc + class Container + class Executable < Naked + def self.me?(criteria) + return true if criteria.magic_number(/^#!\s*\S+/) + + begin + MachO.open(criteria.path).header.executable? + rescue MachO::MagicError + false + end + end + end + end +end diff --git a/Library/Homebrew/cask/lib/hbc/utils.rb b/Library/Homebrew/cask/lib/hbc/utils.rb index 3fc817dd5..ecb565e8e 100644 --- a/Library/Homebrew/cask/lib/hbc/utils.rb +++ b/Library/Homebrew/cask/lib/hbc/utils.rb @@ -4,8 +4,7 @@ require "stringio" require "hbc/utils/file" -PREBUG_URL = "https://github.com/caskroom/homebrew-cask/blob/master/doc/reporting_bugs/pre_bug_report.md".freeze -ISSUES_URL = "https://github.com/caskroom/homebrew-cask#reporting-bugs".freeze +BUG_REPORTS_URL = "https://github.com/caskroom/homebrew-cask#reporting-bugs".freeze # monkeypatch Object - not a great idea class Object @@ -39,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 @@ -96,11 +103,7 @@ module Hbc def self.error_message_with_suggestions <<-EOS.undent Follow the instructions here: - #{Formatter.url(PREBUG_URL)} - - If this doesn’t fix the problem, please report this bug: - #{Formatter.url(ISSUES_URL)} - + #{Formatter.url(BUG_REPORTS_URL)} EOS end |
