Class: UnpackStrategy::Dmg Private

Inherits:
Object show all
Extended by:
SystemCommand::Mixin, ClassMethods
Includes:
UnpackStrategy
Defined in:
unpack_strategy/dmg.rb,
extend/os/mac/unpack_strategy/dmg.rb

Overview

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Strategy for unpacking disk images.

Defined Under Namespace

Modules: Bom Classes: Mount

Constant Summary

Constants included from UnpackStrategy

UnpackStrategyType

Instance Attribute Summary

Attributes included from UnpackStrategy

#merge_xattrs, #path, #temporary_directory

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SystemCommand::Mixin

command_sandbox, system_command, system_command!

Methods included from ClassMethods

can_extract?, extensions

Methods included from UnpackStrategy

#dependencies, detect, #each_directory, #extract, #extract_nestedly, from_extension, from_magic, from_name, from_type, #initialize

Methods included from Utils::Output::Mixin

#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_once, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_incompatible, #pretty_install_status, #pretty_installed, #pretty_removed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning

Class Method Details

.can_extract?(path) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:

  • (Boolean)


187
188
189
190
# File 'unpack_strategy/dmg.rb', line 187

def self.can_extract?(path)
  stdout, _, status = system_command("hdiutil", args: ["imageinfo", "-format", path], print_stderr: false).to_a
  (status.success? && !stdout.empty?) || false
end

.diskutil_image? ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


193
# File 'unpack_strategy/dmg.rb', line 193

def self.diskutil_image? = false

.extensions ⇒ Array<String>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



182
183
184
# File 'unpack_strategy/dmg.rb', line 182

def self.extensions
  [".dmg"]
end

Instance Method Details

#mount(verbose: false, &_block) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:

  • verbose (Boolean) (defaults to: false)
  • _block (T.proc.params(arg0: T::Array[Mount]).void)


196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'unpack_strategy/dmg.rb', line 196

def mount(verbose: false, &_block)
  Dir.mktmpdir("homebrew-dmg", HOMEBREW_TEMP) do |mount_dir|
    mount_dir = Pathname(mount_dir)

    plist = attach_with_diskutil(mount_dir, verbose:) if self.class.diskutil_image?
    plist ||= attach_with_hdiutil(mount_dir, verbose:)

    mounts = if plist.respond_to?(:fetch)
      plist.fetch("system-entities", [])
           .filter_map { |entity| entity["mount-point"] }
           .map { |path| Mount.new(path) }
    else
      []
    end

    begin
      yield mounts
    ensure
      mounts.each do |mount|
        mount.eject(verbose:)
      end
    end
  end
rescue ErrorDuringExecution => e
  raise unless e.stderr.include?("There may be a problem with this disk image.")
  raise unless e.stderr.include?("hdiutil: attach canceled")

  raise e.exception(<<~EOS), cause: nil
    macOS refused to mount the disk image:
      #{path}
    Its filesystem may be damaged or inconsistent.
    Report this to the software vendor and request a corrected disk image.

    #{e.message}
  EOS
end