Class: PuppetForge::Unpacker
- Inherits:
-
Object
- Object
- PuppetForge::Unpacker
- Defined in:
- lib/shared/puppet_forge/unpacker.rb
Class Method Summary collapse
-
.harmonize_ownership(source, target) ⇒ Object
Set the owner/group of the target directory to those of the source Note: don’t call this function on Microsoft Windows.
-
.unpack(filename, target, tmpdir) ⇒ Hash{:symbol => Array<String>}
Unpack a tar file into a specified directory.
Instance Method Summary collapse
-
#initialize(filename, target, tmpdir) ⇒ Unpacker
constructor
A new instance of Unpacker.
- #move_into(dir) ⇒ Object private
- #root_dir ⇒ Object private
- #unpack ⇒ Object private
Constructor Details
#initialize(filename, target, tmpdir) ⇒ Unpacker
Returns a new instance of Unpacker.
31 32 33 34 35 |
# File 'lib/shared/puppet_forge/unpacker.rb', line 31 def initialize(filename, target, tmpdir) @filename = filename @target = target @tmpdir = tmpdir end |
Class Method Details
.harmonize_ownership(source, target) ⇒ Object
Set the owner/group of the target directory to those of the source Note: don’t call this function on Microsoft Windows
25 26 27 |
# File 'lib/shared/puppet_forge/unpacker.rb', line 25 def self.harmonize_ownership(source, target) FileUtils.chown_R(source.stat.uid, source.stat.gid, target) end |
.unpack(filename, target, tmpdir) ⇒ Hash{:symbol => Array<String>}
Unpack a tar file into a specified directory
13 14 15 16 17 18 |
# File 'lib/shared/puppet_forge/unpacker.rb', line 13 def self.unpack(filename, target, tmpdir) inst = self.new(filename, target, tmpdir) file_lists = inst.unpack inst.move_into(Pathname.new(target)) file_lists end |
Instance Method Details
#move_into(dir) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
47 48 49 50 51 52 |
# File 'lib/shared/puppet_forge/unpacker.rb', line 47 def move_into(dir) dir.rmtree if dir.exist? FileUtils.mv(root_dir, dir) ensure FileUtils.rmtree(@tmpdir) end |
#root_dir ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/shared/puppet_forge/unpacker.rb', line 55 def root_dir return @root_dir if @root_dir # Grab the first directory containing a metadata.json file = Dir["#{@tmpdir}/**/metadata.json"].sort_by(&:length)[0] if @root_dir = Pathname.new().dirname else raise "No valid metadata.json found!" end end |
#unpack ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
38 39 40 41 42 43 44 |
# File 'lib/shared/puppet_forge/unpacker.rb', line 38 def unpack begin PuppetForge::Tar.instance.unpack(@filename, @tmpdir) rescue PuppetForge::ExecutionFailure => e raise RuntimeError, "Could not extract contents of module archive: #{e.}" end end |