Class: Tarball

Inherits:
Object
  • 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
# File 'lib/tarball.rb', line 24

def list
  output = LoggedCheetah.run("tar", "tvf", @file, :stdout => :capture)

  output.lines.map do |line|
    mode, user_and_group, size, date, time, *rest = line.split(" ")

    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.join(" ").split(" -> ").first
      when "d"
        type = :dir
        path = rest.join(" ")[0..-2]   # Strip trailing "/".
      else
        type = :file
        path = rest.join(" ")
    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