Module: Utils::Tar Private

Extended by:
SystemCommand::Mixin
Defined in:
utils/tar.rb

Overview

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

Helper functions for interacting with tar files.

Constant Summary collapse

TAR_FILE_EXTENSIONS =

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

%w[.tar .tb2 .tbz .tbz2 .tgz .tlz .txz .tZ].freeze

Class Method Summary collapse

Methods included from SystemCommand::Mixin

system_command, system_command!

Class Method Details

.available?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)


15
16
17
# File 'utils/tar.rb', line 15

def available?
  executable.present?
end

.clear_executable_cachevoid

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.



40
41
42
# File 'utils/tar.rb', line 40

def clear_executable_cache
  remove_instance_variable(:@executable) if defined?(@executable)
end

.executablePathname?

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:



20
21
22
23
24
25
26
# File 'utils/tar.rb', line 20

def executable
  return @executable if defined?(@executable)

  gnu_tar_gtar_path = HOMEBREW_PREFIX/"opt/gnu-tar/bin/gtar"
  gnu_tar_gtar = gnu_tar_gtar_path if gnu_tar_gtar_path.executable?
  @executable = T.let((which("gtar") || gnu_tar_gtar || which("tar")), T.nilable(Pathname))
end

.validate_file(path) ⇒ 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:



29
30
31
32
33
34
35
36
37
# File 'utils/tar.rb', line 29

def validate_file(path)
  return unless available?

  path = Pathname.new(path)
  return unless TAR_FILE_EXTENSIONS.include? path.extname

  stdout, _, status = system_command(executable, args: ["--list", "--file", path], print_stderr: false)
  odie "#{path} is not a valid tar file!" if !status.success? || stdout.blank?
end