class Puppet::ModuleTool::Applications::Unpacker

Public Class Methods

harmonize_ownership(source, target) click to toggle source
   # File lib/puppet/module_tool/applications/unpacker.rb
17 def self.harmonize_ownership(source, target)
18   unless Puppet::Util::Platform.windows?
19     source = Pathname.new(source) unless source.respond_to?(:stat)
20     target = Pathname.new(target) unless target.respond_to?(:stat)
21 
22     FileUtils.chown_R(source.stat.uid, source.stat.gid, target)
23   end
24 end
new(filename, options = {}) click to toggle source
   # File lib/puppet/module_tool/applications/unpacker.rb
26 def initialize(filename, options = {})
27   @filename = Pathname.new(filename)
28   super(options)
29   @module_path = Pathname(options[:target_dir])
30 end
unpack(filename, target) click to toggle source
   # File lib/puppet/module_tool/applications/unpacker.rb
10 def self.unpack(filename, target)
11   app = self.new(filename, :target_dir => target)
12   app.unpack
13   app.sanity_check
14   app.move_into(target)
15 end

Public Instance Methods

module_name() click to toggle source

@api private

   # File lib/puppet/module_tool/applications/unpacker.rb
78 def module_name
79   metadata = Puppet::Util::Json.load((root_dir + 'metadata.json').read)
80   metadata['name'][/-(.*)/, 1]
81 end
move_into(dir) click to toggle source

@api private

   # File lib/puppet/module_tool/applications/unpacker.rb
84 def move_into(dir)
85   dir = Pathname.new(dir)
86   dir.rmtree if dir.exist?
87   FileUtils.mv(root_dir, dir)
88 ensure
89   FileUtils.rmtree(tmpdir)
90 end
root_dir() click to toggle source

@api private

   # File lib/puppet/module_tool/applications/unpacker.rb
64 def root_dir
65   return @root_dir if @root_dir
66 
67   # Grab the first directory containing a metadata.json file
68   metadata_file = Dir["#{tmpdir}/**/metadata.json"].sort_by(&:length)[0]
69 
70   if metadata_file
71     @root_dir = Pathname.new(metadata_file).dirname
72   else
73     raise _("No valid metadata.json found!")
74   end
75 end
run() click to toggle source
   # File lib/puppet/module_tool/applications/unpacker.rb
32 def run
33   unpack
34   sanity_check
35   module_dir = @module_path + module_name
36   move_into(module_dir)
37 
38   # Return the Pathname object representing the directory where the
39   # module release archive was unpacked the to.
40   return module_dir
41 end
sanity_check() click to toggle source

@api private Error on symlinks and other junk

   # File lib/puppet/module_tool/applications/unpacker.rb
45 def sanity_check
46   symlinks = Dir.glob("#{tmpdir}/**/*", File::FNM_DOTMATCH).map { |f| Pathname.new(f) }.select {|p| Puppet::FileSystem.symlink? p}
47   tmpdirpath = Pathname.new tmpdir
48 
49   symlinks.each do |s|
50     Puppet.warning _("Symlinks in modules are unsupported. Please investigate symlink %{from}->%{to}.") % { from: s.relative_path_from(tmpdirpath), to: Puppet::FileSystem.readlink(s) }
51   end
52 end
tmpdir() click to toggle source

Obtain a suitable temporary path for unpacking tarballs

@api private @return [String] path to temporary unpacking location

   # File lib/puppet/module_tool/applications/unpacker.rb
96 def tmpdir
97   @dir ||= Dir.mktmpdir('tmp', Puppet::Forge::Cache.base_path)
98 end
unpack() click to toggle source

@api private

   # File lib/puppet/module_tool/applications/unpacker.rb
55 def unpack
56   begin
57     Puppet::ModuleTool::Tar.instance.unpack(@filename.to_s, tmpdir, [@module_path.stat.uid, @module_path.stat.gid].join(':'))
58   rescue Puppet::ExecutionFailure => e
59     raise RuntimeError, _("Could not extract contents of module archive: %{message}") % { message: e.message }
60   end
61 end