23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/iesd/utility/hdiutil.rb', line 23
def self.write input, output, options = {}
options = {
:resize => {
:grow => 0,
:shrink => false
}
}.merge(options)
Dir.mktmpdir { |tmp|
shadow = File.join(tmp, "#{File.basename input}.shadow")
shadow_options = ["-shadow", shadow]
format_options = ["-format", `/usr/bin/env hdiutil imageinfo -format #{input.shellescape}`.chomp]
Dir.mktmpdir(nil, tmp) { |mountpoint|
resize_limits = `/usr/bin/env hdiutil resize -limits -shadow #{shadow.shellescape} #{input.shellescape}`.chomp.split.map { |s| s.to_i }
sectors = (resize_limits[1] + options[:resize][:grow]).to_s
system("/usr/bin/env", "hdiutil", "resize", "-growonly", "-sectors", sectors, *shadow_options, input)
attach input, mountpoint, [*DEFAULT_MOUNT_OPTIONS, *shadow_options]
if block_given?
yield mountpoint
else
shell mountpoint
end
detach input, mountpoint, [*DEFAULT_UNMOUNT_OPTIONS]
system("/usr/bin/env", "hdiutil", "resize", "-shrinkonly", "-sectors", "min", *shadow_options, input) if options[:resize][:shrink]
}
oh1 "Merging #{shadow}"
system("/usr/bin/env", "hdiutil", "convert", *DEFAULT_CONVERT_OPTIONS, *format_options, *shadow_options, "-o", output, input)
puts "Merged: #{output}"
}
end
|