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.
7 8 9 |
# File 'lib/fpm/fry/tar.rb', line 7 def initialize( = {} ) @logger = .fetch(:logger){ Cabin::Channel.get } end |
Instance Method Details
#chown(uid, gid, path) ⇒ Object
53 54 55 56 57 |
# File 'lib/fpm/fry/tar.rb', line 53 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
11 12 13 14 15 |
# File 'lib/fpm/fry/tar.rb', line 11 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
17 18 19 20 21 22 23 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 |
# File 'lib/fpm/fry/tar.rb', line 17 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
63 64 65 |
# File 'lib/fpm/fry/tar.rb', line 63 def map_group( gid, _ ) return gid end |
#map_user(uid, _) ⇒ Object
59 60 61 |
# File 'lib/fpm/fry/tar.rb', line 59 def map_user( uid, _ ) return uid end |