Module: Utils::Tar Private

Defined in:
brew/Library/Homebrew/utils/tar.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Helper functions for interacting with tar files.

Constant Summary collapse

TAR_FILE_EXTENSIONS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

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

Class Method Summary collapse

Class Method Details

.available?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


12
13
14
# File 'brew/Library/Homebrew/utils/tar.rb', line 12

def available?
  executable.present?
end

.clear_executable_cacheObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



34
35
36
# File 'brew/Library/Homebrew/utils/tar.rb', line 34

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

.executableObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



16
17
18
19
20
21
22
# File 'brew/Library/Homebrew/utils/tar.rb', line 16

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. You should avoid using this method if possible, as it may be removed or be changed in the future.



24
25
26
27
28
29
30
31
32
# File 'brew/Library/Homebrew/utils/tar.rb', line 24

def validate_file(path)
  return unless available?

  path = Pathname.new(path)
  return unless TAR_FILE_EXTENSIONS.include? path.extname
  return if Utils.popen_read(executable, "-tf", path).match?(%r{/.*\.})

  odie "#{path} is not a valid tar file!"
end