Class: PuppetForge::Unpacker
- Inherits:
-
Object
- Object
- PuppetForge::Unpacker
- Defined in:
- lib/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.
32 33 34 35 36 |
# File 'lib/puppet_forge/unpacker.rb', line 32 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
26 27 28 |
# File 'lib/puppet_forge/unpacker.rb', line 26 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
14 15 16 17 18 19 |
# File 'lib/puppet_forge/unpacker.rb', line 14 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.
48 49 50 51 52 53 |
# File 'lib/puppet_forge/unpacker.rb', line 48 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.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/puppet_forge/unpacker.rb', line 56 def root_dir return @root_dir if @root_dir # Use Find.find instead of Dir[] for Windows long path support = nil shortest_length = Float::INFINITY begin Find.find(@tmpdir) do |path| if File.basename(path) == 'metadata.json' if path.length < shortest_length = path shortest_length = path.length end end end rescue Errno::ENAMETOOLONG => e # Even Find.find might fail, need to use Dir.each with manual recursion raise "Cannot traverse directory due to long paths: #{e.}" end 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.
39 40 41 42 43 44 45 |
# File 'lib/puppet_forge/unpacker.rb', line 39 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 |