homebrew-cask-versions/lib/hbc/container/dmg.rb
Paul Hinze 05dc81431d 10.10.3 fix: pull bsexec from mount commands
It seems like in 10.10.3 apple, in its infinite wisdom, decided that the
bsexec option for launchctl would suddenly require root privileges.

Since we were proactively using bsexec for all DMG mounts, this was
breaking dmg-based Casks for all early adopters of 10.10.3.

We can regroup to try and address #7132 another way, but for now, just
pulling all the bsexec stuff out.
2015-02-08 08:23:42 -06:00

72 lines
2.2 KiB
Ruby

class Hbc::Container::Dmg < Hbc::Container::Base
def self.me?(criteria)
criteria.imageinfo != ''
end
attr_reader :mounts
def initialize(*args)
super(*args)
@mounts = []
end
def extract
mount!
assert_mounts_found
@mounts.each do |mount|
@command.run('/usr/bin/ditto',
# todo
# per https://github.com/caskroom/homebrew-cask/issues/6382, ditto
# complains to stderr about unreadable .Trashes directories, so all
# stderr output is silenced for now. But better solutions would be
# - use the --bom option to ditto to selectively avoid certain files
# - .Trashes
# - symlinks to Applications
# - or support some type of text filter to be passed to
# :print_stderr instead of true/false
:print_stderr => false,
:args => ['--', mount, @cask.staged_path])
end
ensure
eject!
end
def mount!
plist = @command.run('/usr/bin/hdiutil',
# realpath is a failsafe against unusual filenames
:args => %w[mount -plist -nobrowse -readonly -noidme -mountrandom /tmp] + [Pathname.new(@path).realpath],
:input => %w[y]
).plist
@mounts = mounts_from_plist(plist)
end
def mounts_from_plist(plist)
return [] unless plist.respond_to?(:fetch)
plist.fetch('system-entities', []).map do |entity|
entity['mount-point']
end.compact
end
def assert_mounts_found
if @mounts.empty?
raise Hbc::CaskError.new %Q{No mounts found in '#{@path}'; perhaps it is a bad DMG?}
end
end
def eject!
@mounts.each do |mount|
# realpath is a failsafe against unusual filenames
mountpath = Pathname.new(mount).realpath
next unless mountpath.exist?
@command.run('/usr/sbin/diskutil',
:args => ['eject', mountpath],
:print_stderr => false)
next unless mountpath.exist?
sleep 1
@command.run('/usr/sbin/diskutil',
:args => ['eject', mountpath],
:print_stderr => false)
next unless mountpath.exist?
raise Hbc::CaskError.new "Failed to eject #{mountpath}"
end
end
end