Class: Onboard::Extract

Inherits:
Object
  • Object
show all
Defined in:
lib/onboard/extract.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(archive, link, path) ⇒ Extract

Returns a new instance of Extract.



14
15
16
17
18
# File 'lib/onboard/extract.rb', line 14

def initialize(archive, link, path)
  @archive = archive
  @link = link
  @path = path
end

Instance Attribute Details

#archiveObject (readonly)

Returns the value of attribute archive.



12
13
14
# File 'lib/onboard/extract.rb', line 12

def archive
  @archive
end

Returns the value of attribute link.



12
13
14
# File 'lib/onboard/extract.rb', line 12

def link
  @link
end

#pathObject (readonly)

Returns the value of attribute path.



12
13
14
# File 'lib/onboard/extract.rb', line 12

def path
  @path
end

Instance Method Details



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

def longlink(entry)
  return File.join path, entry.read.strip if entry.full_name == TAR_LONGLINK
end

#x(dst = nil) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/onboard/extract.rb', line 44

def x(dst = nil)
  Gem::Package::TarReader.new(Zlib::GzipReader.open archive) do |tar|
    tar.each do |entry|
      dst = longlink(entry)
      dst ||= File.join path, entry.full_name
      xdir(dst, entry)
      xfile(dst, entry)
      xlink(dst, entry)
      dst = nil
    end
  end
end

#xdir(dst, entry) ⇒ Object



24
25
26
27
28
# File 'lib/onboard/extract.rb', line 24

def xdir(dst, entry)
  return false unless entry.directory?
  FileUtils.rm_rf dst unless File.directory? dst
  FileUtils.mkdir_p dst, :mode => entry.header.mode, :verbose => false
end

#xfile(dst, entry) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/onboard/extract.rb', line 30

def xfile(dst, entry)
  return false unless entry.file?
  FileUtils.rm_rf dst unless File.file? dst
  File.open dst, 'wb' do |f|
    f.print entry.read
  end
  FileUtils.chmod entry.header.mode, dst, :verbose => false
end


39
40
41
42
# File 'lib/onboard/extract.rb', line 39

def xlink(dst, entry)
  return false unless entry.header.typeflag == '2' # Symlink!
  File.symlink entry.header.linkname, dst
end