class PuppetForge::Unpacker
Public Class Methods
harmonize_ownership(source, target)
click to toggle source
Set the owner/group of the target directory to those of the source Note: don't call this function on Microsoft Windows
@param source [Pathname] source of the permissions @param target [Pathname] target of the permissions change
# File lib/puppet_forge/unpacker.rb, line 25 def self.harmonize_ownership(source, target) FileUtils.chown_R(source.stat.uid, source.stat.gid, target) end
new(filename, target, tmpdir)
click to toggle source
@param filename [String] the file to unpack @param target [String] the target directory to unpack into
# File lib/puppet_forge/unpacker.rb, line 31 def initialize(filename, target, tmpdir) @filename = filename @target = target @tmpdir = tmpdir end
unpack(filename, target, tmpdir)
click to toggle source
Unpack a tar file into a specified directory
@param filename [String] the file to unpack @param target [String] the target directory to unpack into @return [Hash{:symbol => Array<String>}] a hash with file-category keys pointing to lists of filenames.
The categories are :valid, :invalid and :symlink
# File lib/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
Public Instance Methods
move_into(dir)
click to toggle source
@api private
# File lib/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()
click to toggle source
@api private
# File lib/puppet_forge/unpacker.rb, line 55 def root_dir return @root_dir if @root_dir # Grab the first directory containing a metadata.json file metadata_file = Dir["#{@tmpdir}/**/metadata.json"].sort_by(&:length)[0] if metadata_file @root_dir = Pathname.new(metadata_file).dirname else raise "No valid metadata.json found!" end end
unpack()
click to toggle source
@api private
# File lib/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.message}" end end