Module: UnpackStrategy::Dmg::Bom

Extended by:
SystemCommand::Mixin
Defined in:
unpack_strategy/dmg.rb

Overview

Helper module for listing the contents of a volume mounted from a disk image.

Defined Under Namespace

Classes: EmptyError, Error

Class Method Summary collapse

Methods included from SystemCommand::Mixin

system_command, system_command!

Class Method Details

.bom(pathname) ⇒ String

Parameters:

Returns:

Raises:



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'unpack_strategy/dmg.rb', line 53

def self.bom(pathname)
  tries = 0
  result = loop do
    # We need to use `find` here instead of Ruby in order to properly handle
    # file names containing special characters, such as “e” + “´” vs. “é”.
    r = system_command("find", args: [".", "-print0"], chdir: pathname, print_stderr: false)
    tries += 1

    # Spurious bug on CI, which in most cases can be worked around by retrying.
    break r unless r.stderr.match?(/Interrupted system call/i)

    raise "Command `#{r.command.shelljoin}` was interrupted." if tries >= 3
  end

  odebug "Command `#{result.command.shelljoin}` in '#{pathname}' took #{tries} tries." if tries > 1

  bom_paths = result.stdout.split("\0")

  raise EmptyError, pathname if bom_paths.empty?

  bom_paths
    .reject { |path| dmg_metadata?(Pathname(path)) }
    .reject { |path| system_dir_symlink?(pathname/path) }
    .join("\n")
end

.dmg_metadata?(pathname) ⇒ Boolean

Check if path is considered disk image metadata.

Parameters:

Returns:

  • (Boolean)


42
43
44
# File 'unpack_strategy/dmg.rb', line 42

def self.dmg_metadata?(pathname)
  DMG_METADATA.include?(pathname.cleanpath.ascend.to_a.last.to_s)
end

.system_dir_symlink?(pathname) ⇒ Boolean

Check if path is a symlink to a system directory (commonly to /Applications).

Parameters:

Returns:

  • (Boolean)


48
49
50
# File 'unpack_strategy/dmg.rb', line 48

def self.system_dir_symlink?(pathname)
  pathname.symlink? && MacOS.system_dir?(pathname.dirname.join(pathname.readlink))
end