Class: Machinery::Tarball

Inherits:
Object show all
Defined in:
lib/tarball.rb

Overview

Represents a tarball, possibly gzipped.

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Tarball

Returns a new instance of Tarball.



20
21
22
# File 'lib/tarball.rb', line 20

def initialize(file)
  @file = file
end

Instance Method Details

#listObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/tarball.rb', line 24

def list
  output = Machinery::LoggedCheetah.run(
    "tar",
    "tvf",
    @file,
    "--quoting-style=literal",
    stdout: :capture
  )

  output.lines.map do |line|
    mode, user_and_group, size, _date, _time, rest = line.split(" ", 6)

    case mode[0]
    when "l"
      type = :link
      # This may fail for files with "->" in their name, but there is no way
      # how to avoid this when using "tar".
      path = rest.split(" -> ").first
    when "h"
      type = :file
      # This may fail for files with "link to" in their name, but there is no way
      # how to avoid this when using "tar" unless we use the parameter
      # --hard-dereference with tar to get rid of hard links
      path = rest.split(" link to ").first
    when "d"
      type = :dir
      path = rest.chomp("/\n")
    else
      type = :file
      path = rest.chomp
    end

    user, group = user_and_group.split("/")

    {
      path:  path,
      type:  type,
      size:  size.to_i,
      mode:  mode_string_to_octal(mode),
      user:  user,
      group: group
    }
  end
end