mirror of
https://github.com/donl/homebrew-cask-versions.git
synced 2026-07-17 14:26:45 -06:00
- add `run!` method which raises if command does not succeed - use `run!` when the command we are running must succeed for things to move forward. this should help produce clearer error messages in failure scenarios. - move caveats earlier in the install process so reports can be made about potential failures - remove the destination tree on cask install failure, so the cask will not be considered installed
48 lines
999 B
Ruby
48 lines
999 B
Ruby
class Cask::Container::Dmg < Cask::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('ditto', :args => [mount, @cask.destination_path])
|
|
end
|
|
ensure
|
|
eject!
|
|
end
|
|
|
|
def mount!
|
|
plist = @command.run!('hdiutil',
|
|
:args => %w[mount -plist -nobrowse -readonly -noidme -mountrandom /tmp] + [@path],
|
|
:input => %w[y],
|
|
:plist => true
|
|
)
|
|
@mounts = mounts_from_plist(plist)
|
|
end
|
|
|
|
def mounts_from_plist(plist)
|
|
plist.fetch('system-entities', []).map do |entity|
|
|
entity['mount-point']
|
|
end.compact
|
|
end
|
|
|
|
def assert_mounts_found
|
|
if @mounts.empty?
|
|
raise "no mounts found in #{@path}; perhaps its a bad dmg?"
|
|
end
|
|
end
|
|
|
|
def eject!
|
|
@mounts.each do |mount|
|
|
@command.run!('hdiutil', :args => ['eject', mount])
|
|
end
|
|
end
|
|
end
|