Don't use CaskError in Hbc::Container::Dmg.
This commit is contained in:
parent
e5e8033145
commit
1ccd1c0017
@ -15,9 +15,9 @@ module Hbc
|
|||||||
end
|
end
|
||||||
|
|
||||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||||
mount do |mounts|
|
mount(verbose: verbose) do |mounts|
|
||||||
begin
|
begin
|
||||||
raise CaskError, "No mounts found in '#{@path}'; perhaps it is a bad disk image?" if mounts.empty?
|
raise "No mounts found in '#{path}'; perhaps it is a bad disk image?" if mounts.empty?
|
||||||
mounts.each do |mount|
|
mounts.each do |mount|
|
||||||
extract_mount(mount, to: unpack_dir)
|
extract_mount(mount, to: unpack_dir)
|
||||||
end
|
end
|
||||||
@ -27,13 +27,12 @@ module Hbc
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def mount
|
def mount(verbose: false)
|
||||||
# realpath is a failsafe against unusual filenames
|
# realpath is a failsafe against unusual filenames
|
||||||
path = Pathname.new(@path).realpath
|
realpath = path.realpath
|
||||||
|
path = realpath
|
||||||
|
|
||||||
Dir.mktmpdir do |unpack_dir|
|
Dir.mktmpdir do |unpack_dir|
|
||||||
cdr_path = Pathname.new(unpack_dir).join("#{path.basename(".dmg")}.cdr")
|
|
||||||
|
|
||||||
without_eula = system_command("/usr/bin/hdiutil",
|
without_eula = system_command("/usr/bin/hdiutil",
|
||||||
args: ["attach", "-plist", "-nobrowse", "-readonly", "-noidme", "-mountrandom", unpack_dir, path],
|
args: ["attach", "-plist", "-nobrowse", "-readonly", "-noidme", "-mountrandom", unpack_dir, path],
|
||||||
input: "qn\n",
|
input: "qn\n",
|
||||||
@ -43,12 +42,14 @@ module Hbc
|
|||||||
plist = if without_eula.success?
|
plist = if without_eula.success?
|
||||||
without_eula.plist
|
without_eula.plist
|
||||||
else
|
else
|
||||||
|
cdr_path = Pathname.new(unpack_dir).join("#{path.basename(".dmg")}.cdr")
|
||||||
|
|
||||||
system_command!("/usr/bin/hdiutil", args: ["convert", "-quiet", "-format", "UDTO", "-o", cdr_path, path])
|
system_command!("/usr/bin/hdiutil", args: ["convert", "-quiet", "-format", "UDTO", "-o", cdr_path, path])
|
||||||
|
|
||||||
with_eula = system_command!("/usr/bin/hdiutil",
|
with_eula = system_command!("/usr/bin/hdiutil",
|
||||||
args: ["attach", "-plist", "-nobrowse", "-readonly", "-noidme", "-mountrandom", unpack_dir, cdr_path])
|
args: ["attach", "-plist", "-nobrowse", "-readonly", "-noidme", "-mountrandom", unpack_dir, cdr_path])
|
||||||
|
|
||||||
if verbose? && !(eula_text = without_eula.stdout).empty?
|
if verbose && !(eula_text = without_eula.stdout).empty?
|
||||||
ohai "Software License Agreement for '#{path}':"
|
ohai "Software License Agreement for '#{path}':"
|
||||||
puts eula_text
|
puts eula_text
|
||||||
end
|
end
|
||||||
@ -63,21 +64,22 @@ module Hbc
|
|||||||
def eject(mount)
|
def eject(mount)
|
||||||
# realpath is a failsafe against unusual filenames
|
# realpath is a failsafe against unusual filenames
|
||||||
mountpath = Pathname.new(mount).realpath
|
mountpath = Pathname.new(mount).realpath
|
||||||
return unless mountpath.exist?
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
tries ||= 3
|
tries ||= 3
|
||||||
|
|
||||||
|
return unless mountpath.exist?
|
||||||
|
|
||||||
if tries > 1
|
if tries > 1
|
||||||
system_command("/usr/sbin/diskutil",
|
system_command!("/usr/sbin/diskutil",
|
||||||
args: ["eject", mountpath],
|
args: ["eject", mountpath],
|
||||||
print_stderr: false)
|
print_stderr: false)
|
||||||
else
|
else
|
||||||
system_command("/usr/sbin/diskutil",
|
system_command!("/usr/sbin/diskutil",
|
||||||
args: ["unmount", "force", mountpath],
|
args: ["unmount", "force", mountpath],
|
||||||
print_stderr: false)
|
print_stderr: false)
|
||||||
end
|
end
|
||||||
raise CaskError, "Failed to eject #{mountpath}" if mountpath.exist?
|
rescue ErrorDuringExecution => e
|
||||||
rescue CaskError => e
|
|
||||||
raise e if (tries -= 1).zero?
|
raise e if (tries -= 1).zero?
|
||||||
sleep 1
|
sleep 1
|
||||||
retry
|
retry
|
||||||
@ -111,7 +113,7 @@ module Hbc
|
|||||||
end
|
end
|
||||||
|
|
||||||
def skip_path?(mount, path)
|
def skip_path?(mount, path)
|
||||||
path = Pathname(path.sub(%r{^\./}, ""))
|
path = Pathname(path.sub(%r{\A\./}, ""))
|
||||||
dmg_metadata?(path) || system_dir_symlink?(mount, path)
|
dmg_metadata?(path) || system_dir_symlink?(mount, path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user