Class: UnpackStrategy::Tar

Inherits:
Object show all
Extended by:
SystemCommand::Mixin
Includes:
UnpackStrategy
Defined in:
unpack_strategy/tar.rb

Overview

Strategy for unpacking tar archives.

Direct Known Subclasses

Compress

Instance Attribute Summary

Attributes included from UnpackStrategy

#merge_xattrs, #path

Class Method Summary collapse

Methods included from SystemCommand::Mixin

system_command, system_command!

Methods included from UnpackStrategy

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

Class Method Details

.can_extract?(path) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
32
# File 'unpack_strategy/tar.rb', line 24

def self.can_extract?(path)
  return true if path.magic_number.match?(/\A.{257}ustar/n)

  return false unless [Bzip2, Gzip, Lzip, Xz, Zstd].any? { |s| s.can_extract?(path) }

  # Check if `tar` can list the contents, then it can also extract it.
  stdout, _, status = system_command("tar", args: ["--list", "--file", path], print_stderr: false)
  status.success? && !stdout.empty?
end

.extensionsArray<String>

Returns:



13
14
15
16
17
18
19
20
21
22
# File 'unpack_strategy/tar.rb', line 13

def self.extensions
  [
    ".tar",
    ".tbz", ".tbz2", ".tar.bz2",
    ".tgz", ".tar.gz",
    ".tlzma", ".tar.lzma",
    ".txz", ".tar.xz",
    ".tar.zst"
  ]
end