diff --git a/lib/puppet/module_tool/tar.rb b/lib/puppet/module_tool/tar.rb index 6b844545a..cf31f556a 100644 --- a/lib/puppet/module_tool/tar.rb +++ b/lib/puppet/module_tool/tar.rb @@ -1,21 +1,17 @@ require 'puppet/module_tool' require 'puppet/util' module Puppet::ModuleTool::Tar require 'puppet/module_tool/tar/gnu' - require 'puppet/module_tool/tar/solaris' require 'puppet/module_tool/tar/mini' def self.instance(module_name) - gtar_platforms = ['Solaris', 'OpenBSD'] - if gtar_platforms.include?(Facter.value('osfamily')) && Puppet::Util.which('gtar') - Solaris.new - elsif Puppet::Util.which('tar') && ! Puppet::Util::Platform.windows? + if Puppet::Util.which('tar') && ! Puppet::Util::Platform.windows? Gnu.new elsif Puppet.features.minitar? && Puppet.features.zlib? Mini.new(module_name) else raise RuntimeError, 'No suitable tar implementation found' end end end diff --git a/lib/puppet/module_tool/tar/gnu.rb b/lib/puppet/module_tool/tar/gnu.rb index d8fc3378f..aa5c606d9 100644 --- a/lib/puppet/module_tool/tar/gnu.rb +++ b/lib/puppet/module_tool/tar/gnu.rb @@ -1,16 +1,18 @@ class Puppet::ModuleTool::Tar::Gnu def initialize(command = "tar") @command = command end def unpack(sourcefile, destdir, owner) - Puppet::Util::Execution.execute("#{@command} xzf #{sourcefile} --no-same-owner -C #{destdir}") - Puppet::Util::Execution.execute("find #{destdir} -type d -exec chmod 755 {} +") - Puppet::Util::Execution.execute("find #{destdir} -type f -exec chmod a-wst {} +") - Puppet::Util::Execution.execute("chown -R #{owner} #{destdir}") + Dir.chdir(destdir) do + Puppet::Util::Execution.execute("gzip -dc #{sourcefile} | #{@command} xof -") + Puppet::Util::Execution.execute("find #{destdir} -type d -exec chmod 755 {} +") + Puppet::Util::Execution.execute("find #{destdir} -type f -exec chmod a-wst {} +") + Puppet::Util::Execution.execute("chown -R #{owner} #{destdir}") + end end def pack(sourcedir, destfile) Puppet::Util::Execution.execute("tar cf - #{sourcedir} | gzip -c > #{destfile}") end end diff --git a/lib/puppet/module_tool/tar/solaris.rb b/lib/puppet/module_tool/tar/solaris.rb deleted file mode 100644 index fb3e58bbf..000000000 --- a/lib/puppet/module_tool/tar/solaris.rb +++ /dev/null @@ -1,5 +0,0 @@ -class Puppet::ModuleTool::Tar::Solaris < Puppet::ModuleTool::Tar::Gnu - def initialize - super("gtar") - end -end diff --git a/spec/unit/module_tool/tar/gnu_spec.rb b/spec/unit/module_tool/tar/gnu_spec.rb index 93245da1a..a89ea1c4d 100644 --- a/spec/unit/module_tool/tar/gnu_spec.rb +++ b/spec/unit/module_tool/tar/gnu_spec.rb @@ -1,22 +1,23 @@ require 'spec_helper' require 'puppet/module_tool' describe Puppet::ModuleTool::Tar::Gnu do let(:sourcefile) { '/the/module.tar.gz' } let(:destdir) { '/the/dest/dir' } let(:sourcedir) { '/the/src/dir' } let(:destfile) { '/the/dest/file.tar.gz' } it "unpacks a tar file" do - Puppet::Util::Execution.expects(:execute).with("tar xzf #{sourcefile} --no-same-owner -C #{destdir}") + Dir.expects(:chdir).with(destdir).yields(mock) + Puppet::Util::Execution.expects(:execute).with("gzip -dc #{sourcefile} | tar xof -") Puppet::Util::Execution.expects(:execute).with("find #{destdir} -type d -exec chmod 755 {} +") Puppet::Util::Execution.expects(:execute).with("find #{destdir} -type f -exec chmod a-wst {} +") Puppet::Util::Execution.expects(:execute).with("chown -R #{destdir}") subject.unpack(sourcefile, destdir, '') end it "packs a tar file" do Puppet::Util::Execution.expects(:execute).with("tar cf - #{sourcedir} | gzip -c > #{destfile}") subject.pack(sourcedir, destfile) end end diff --git a/spec/unit/module_tool/tar/solaris_spec.rb b/spec/unit/module_tool/tar/solaris_spec.rb deleted file mode 100644 index 1ca7a6a09..000000000 --- a/spec/unit/module_tool/tar/solaris_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require 'spec_helper' -require 'puppet/module_tool' - -describe Puppet::ModuleTool::Tar::Solaris do - let(:sourcefile) { '/the/module.tar.gz' } - let(:destdir) { '/the/dest/dir' } - let(:sourcedir) { '/the/src/dir' } - let(:destfile) { '/the/dest/file.tar.gz' } - - it "unpacks a tar file" do - Puppet::Util::Execution.expects(:execute).with("gtar xzf #{sourcefile} --no-same-owner -C #{destdir}") - Puppet::Util::Execution.expects(:execute).with("find #{destdir} -type d -exec chmod 755 {} +") - Puppet::Util::Execution.expects(:execute).with("find #{destdir} -type f -exec chmod a-wst {} +") - Puppet::Util::Execution.expects(:execute).with("chown -R #{destdir}") - subject.unpack(sourcefile, destdir, '') - end - - it "packs a tar file" do - Puppet::Util::Execution.expects(:execute).with("tar cf - #{sourcedir} | gzip -c > #{destfile}") - subject.pack(sourcedir, destfile) - end -end diff --git a/spec/unit/module_tool/tar_spec.rb b/spec/unit/module_tool/tar_spec.rb index 75034e5bd..d9315e91c 100644 --- a/spec/unit/module_tool/tar_spec.rb +++ b/spec/unit/module_tool/tar_spec.rb @@ -1,45 +1,31 @@ require 'spec_helper' require 'puppet/module_tool' describe Puppet::ModuleTool::Tar do - it "uses gtar when present on Solaris" do - Facter.stubs(:value).with('osfamily').returns 'Solaris' - Puppet::Util.stubs(:which).with('gtar').returns '/usr/bin/gtar' - - described_class.instance(nil).should be_a_kind_of Puppet::ModuleTool::Tar::Solaris - end - - it "uses gtar when present on OpenBSD" do - Facter.stubs(:value).with('osfamily').returns 'OpenBSD' - Puppet::Util.stubs(:which).with('gtar').returns '/usr/bin/gtar' - - described_class.instance(nil).should be_a_kind_of Puppet::ModuleTool::Tar::Solaris - end - it "uses tar when present and not on Windows" do Facter.stubs(:value).with('osfamily').returns 'ObscureLinuxDistro' Puppet::Util.stubs(:which).with('tar').returns '/usr/bin/tar' Puppet::Util::Platform.stubs(:windows?).returns false described_class.instance(nil).should be_a_kind_of Puppet::ModuleTool::Tar::Gnu end it "falls back to minitar when it and zlib are present" do Facter.stubs(:value).with('osfamily').returns 'Windows' Puppet::Util.stubs(:which).with('tar') Puppet::Util::Platform.stubs(:windows?).returns true Puppet.stubs(:features).returns(stub(:minitar? => true, :zlib? => true)) described_class.instance(nil).should be_a_kind_of Puppet::ModuleTool::Tar::Mini end it "fails when there is no possible implementation" do Facter.stubs(:value).with('osfamily').returns 'Windows' Puppet::Util.stubs(:which).with('tar') Puppet::Util::Platform.stubs(:windows?).returns true Puppet.stubs(:features).returns(stub(:minitar? => false, :zlib? => false)) expect { described_class.instance(nil) }.to raise_error RuntimeError, /No suitable tar/ end end