~ubuntu-branches/ubuntu/quantal/puppet/quantal

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-07-14 01:56:30 UTC
  • mfrom: (1.1.29) (3.1.43 sid)
  • Revision ID: package-import@ubuntu.com-20120714015630-ntj41rkvkq4zph4y
Tags: 2.7.18-1ubuntu1
* Resynchronise with Debian. (LP: #1023931) Remaining changes:
  - debian/puppetmaster-passenger.postinst: Make sure we error if puppet
    config print doesn't work
  - debian/puppetmaster-passenger.postinst: Ensure upgrades from
    <= 2.7.11-1 fixup passenger apache configuration.
* Dropped upstreamed patches:
  - debian/patches/CVE-2012-1906_CVE-2012-1986_to_CVE-2012-1989.patch
  - debian/patches/puppet-12844
  - debian/patches/2.7.17-Puppet-July-2012-CVE-fixes.patch
* Drop Build-Depends on ruby-rspec (in universe):
  - debian/control: remove ruby-rspec from Build-Depends
  - debian/patches/no-rspec.patch: make Rakefile work anyway if rspec
    isn't installed so we can use it in debian/rules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
require 'pathname'
2
2
require 'tmpdir'
3
3
 
4
 
module Puppet::Module::Tool
 
4
module Puppet::ModuleTool
5
5
  module Applications
6
6
    class Unpacker < Application
7
7
 
8
8
      def initialize(filename, options = {})
9
9
        @filename = Pathname.new(filename)
10
 
        parse_filename!
 
10
        parsed = parse_filename(filename)
11
11
        super(options)
12
 
        @module_dir = Pathname.new(options[:install_dir]) + @module_name
 
12
        @module_dir = Pathname.new(options[:target_dir]) + parsed[:dir_name]
13
13
      end
14
14
 
15
15
      def run
16
16
        extract_module_to_install_dir
17
 
        tag_revision
18
17
 
19
18
        # Return the Pathname object representing the directory where the
20
19
        # module release archive was unpacked the to, and the module release
23
22
      end
24
23
 
25
24
      private
26
 
 
27
 
      def tag_revision
28
 
        File.open("#{@module_dir}/REVISION", 'w') do |f|
29
 
          f.puts "module: #{@username}/#{@module_name}"
30
 
          f.puts "version: #{@version}"
31
 
          f.puts "url: file://#{@filename.expand_path}"
32
 
          f.puts "installed: #{Time.now}"
33
 
        end
34
 
      end
35
 
 
36
25
      def extract_module_to_install_dir
37
26
        delete_existing_installation_or_abort!
38
27
 
39
 
        build_dir = Puppet::Module::Tool::Cache.base_path + "tmp-unpacker-#{Digest::SHA1.hexdigest(@filename.basename.to_s)}"
 
28
        build_dir = Puppet::Forge::Cache.base_path + "tmp-unpacker-#{Digest::SHA1.hexdigest(@filename.basename.to_s)}"
40
29
        build_dir.mkpath
41
30
        begin
42
 
          Puppet.notice "Installing #{@filename.basename} to #{@module_dir.expand_path}"
43
31
          unless system "tar xzf #{@filename} -C #{build_dir}"
44
32
            raise RuntimeError, "Could not extract contents of module archive."
45
33
          end
53
41
 
54
42
      def delete_existing_installation_or_abort!
55
43
        return unless @module_dir.exist?
56
 
 
57
 
        if !options[:force]
58
 
          Puppet.warning "Existing module '#{@module_dir.expand_path}' found"
59
 
          response = prompt "Overwrite module installed at #{@module_dir.expand_path}? [y/N]"
60
 
          unless response =~ /y/i
61
 
            raise RuntimeError, "Aborted installation."
62
 
          end
63
 
        end
64
 
 
65
 
        Puppet.warning "Deleting #{@module_dir.expand_path}"
66
 
        FileUtils.rm_rf @module_dir
 
44
        FileUtils.rm_rf(@module_dir, :secure => true)
67
45
      end
68
46
    end
69
47
  end