Class: FPM::Fry::Tar::Extractor
- Inherits:
-
Object
- Object
- FPM::Fry::Tar::Extractor
- Defined in:
- lib/fpm/fry/tar.rb
Instance Method Summary collapse
- #chown(uid, gid, path) ⇒ Object
- #extract(destdir, reader, options = {}) ⇒ Object
- #extract_entry(dest, entry, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Extractor
constructor
A new instance of Extractor.
- #map_group(gid, _) ⇒ Object
- #map_user(uid, _) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Extractor
Returns a new instance of Extractor.
70 71 72 |
# File 'lib/fpm/fry/tar.rb', line 70 def initialize( = {} ) @logger = .fetch(:logger){ Cabin::Channel.get } end |
Instance Method Details
#chown(uid, gid, path) ⇒ Object
116 117 118 119 120 |
# File 'lib/fpm/fry/tar.rb', line 116 def chown( uid, gid, path ) FileUtils.chown( uid, gid, path ) rescue Errno::EPERM @logger.warn('Unable to chown file', 'file' => path, 'uid' => uid, 'gid' => gid) end |
#extract(destdir, reader, options = {}) ⇒ Object
74 75 76 77 78 |
# File 'lib/fpm/fry/tar.rb', line 74 def extract(destdir, reader, = {}) reader.each do |entry| extract_entry(File.join(destdir, entry.full_name), entry, ) end end |
#extract_entry(dest, entry, options = {}) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/fpm/fry/tar.rb', line 80 def extract_entry(dest, entry, = {}) full_name = entry.full_name mode = entry.header.mode destdir = File.dirname(dest) uid = map_user(entry.header.uid, entry.header.uname) gid = map_group(entry.header.gid, entry.header.gname) @logger.debug('Extracting','file' => dest, 'uid'=> uid, 'gid' => gid, 'entry.fullname' => full_name, 'entry.mode' => mode ) case(entry.header.typeflag) when "5" # Directory FileUtils.mkdir_p(dest, :mode => mode) when "2" # Symlink destdir = File.dirname(dest) FileUtils.mkdir_p(destdir, :mode => 0755) File.symlink( entry.header.linkname, dest ) when "0" # File destdir = File.dirname(dest) FileUtils.mkdir_p(destdir, :mode => 0755) File.open(dest, "wb", entry.header.mode) do |os| loop do data = entry.read(4096) break unless data os.write(data) end os.fsync end else @logger.warn('Ignoring unknown tar entry',name: full_name) return end FileUtils.chmod(entry.header.mode, dest) chown( uid, gid, dest ) if .fetch(:chown,true) end |
#map_group(gid, _) ⇒ Object
126 127 128 |
# File 'lib/fpm/fry/tar.rb', line 126 def map_group( gid, _ ) return gid end |
#map_user(uid, _) ⇒ Object
122 123 124 |
# File 'lib/fpm/fry/tar.rb', line 122 def map_user( uid, _ ) return uid end |