Class: Onboard::Extract
- Inherits:
-
Object
- Object
- Onboard::Extract
- Defined in:
- lib/onboard/extract.rb
Instance Attribute Summary collapse
-
#archive ⇒ Object
readonly
Returns the value of attribute archive.
-
#link ⇒ Object
readonly
Returns the value of attribute link.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(archive, link, path) ⇒ Extract
constructor
A new instance of Extract.
- #longlink(entry) ⇒ Object
- #x(dst = nil) ⇒ Object
- #xdir(dst, entry) ⇒ Object
- #xfile(dst, entry) ⇒ Object
- #xlink(dst, entry) ⇒ Object
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
#archive ⇒ Object (readonly)
Returns the value of attribute archive.
12 13 14 |
# File 'lib/onboard/extract.rb', line 12 def archive @archive end |
#link ⇒ Object (readonly)
Returns the value of attribute link.
12 13 14 |
# File 'lib/onboard/extract.rb', line 12 def link @link end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
12 13 14 |
# File 'lib/onboard/extract.rb', line 12 def path @path end |
Instance Method Details
#longlink(entry) ⇒ Object
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 |
#xlink(dst, entry) ⇒ Object
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 |