~bkerensa/ubuntu/raring/puppet/new-upstream-release

« back to all changes in this revision

Viewing changes to lib/puppet/module_tool/applications/unpacker.rb

  • Committer: Benjamin Kerensa
  • Date: 2012-11-21 23:50:52 UTC
  • mfrom: (1.1.30)
  • Revision ID: bkerensa@ubuntu.com-20121121235052-ah7nzabp77sh69gb
New Upstream Release

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
        @module_dir
22
22
      end
23
23
 
 
24
      # Obtain a suitable temporary path for building and unpacking tarballs
 
25
      #
 
26
      # @return [Pathname] path to temporary build location
 
27
      def build_dir
 
28
        Puppet::Forge::Cache.base_path + "tmp-unpacker-#{Digest::SHA1.hexdigest(@filename.basename.to_s)}"
 
29
      end
 
30
 
24
31
      private
25
32
      def extract_module_to_install_dir
26
33
        delete_existing_installation_or_abort!
27
34
 
28
 
        build_dir = Puppet::Forge::Cache.base_path + "tmp-unpacker-#{Digest::SHA1.hexdigest(@filename.basename.to_s)}"
29
35
        build_dir.mkpath
30
36
        begin
31
 
          unless system "tar xzf #{@filename} -C #{build_dir}"
32
 
            raise RuntimeError, "Could not extract contents of module archive."
 
37
          begin
 
38
            if Facter.value('osfamily') == "Solaris"
 
39
              # Solaris tar is not as safe and works differently, so we prefer
 
40
              # gnutar instead.
 
41
              if Puppet::Util.which('gtar')
 
42
                Puppet::Util::Execution.execute("gtar xzf #{@filename} -C #{build_dir}")
 
43
              else
 
44
                raise RuntimeError, "Cannot find the command 'gtar'. Make sure GNU tar is installed, and is in your PATH."
 
45
              end
 
46
            else
 
47
              Puppet::Util::Execution.execute("tar xzf #{@filename} -C #{build_dir}")
 
48
            end
 
49
          rescue Puppet::ExecutionFailure => e
 
50
            raise RuntimeError, "Could not extract contents of module archive: #{e.message}"
33
51
          end
 
52
 
34
53
          # grab the first directory
35
54
          extracted = build_dir.children.detect { |c| c.directory? }
36
55
          FileUtils.mv extracted, @module_dir