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)


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

def available?
  executable.present?
end

.clear_executable_cacheObject

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.



36
37
38
# File 'utils/tar.rb', line 36

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

.executableObject

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.



18
19
20
21
22
23
24
# File 'utils/tar.rb', line 18

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 = which("gtar") || gnu_tar_gtar || which("tar")
end

.validate_file(path) ⇒ Object

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.



26
27
28
29
30
31
32
33
34
# File 'utils/tar.rb', line 26

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