From 8143ffa9d825a976bebb34606ed4f7c27e43785f Mon Sep 17 00:00:00 2001 From: Micha Krause Date: Thu, 24 Sep 2015 13:10:30 +0200 Subject: [PATCH] Added Option to use tar file permissions instead of local umask --- manifests/extract.pp | 13 ++++++++++--- manifests/init.pp | 3 +++ spec/defines/archive_spec.rb | 15 ++++++++++++++- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/manifests/extract.pp b/manifests/extract.pp index b5e47a9..247c34d 100644 --- a/manifests/extract.pp +++ b/manifests/extract.pp @@ -41,6 +41,7 @@ $strip_components=0, $purge=false, $user=undef, + $same_permissions=false, ) { if $root_dir { @@ -49,13 +50,19 @@ $extract_dir = "${target}/${name}" } + if $same_permissions { + $_same_permissions="--same-permissions" + } else { + $_same_permissions="--no-same-permissions" + } + case $ensure { 'present': { $extract_zip = "unzip -o ${src_target}/${name}.${extension} -d ${target}" - $extract_targz = "tar --no-same-owner --no-same-permissions --strip-components=${strip_components} -xzf ${src_target}/${name}.${extension} -C ${target}" - $extract_tarbz2 = "tar --no-same-owner --no-same-permissions --strip-components=${strip_components} -xjf ${src_target}/${name}.${extension} -C ${target}" - $extract_tarxz = "tar --no-same-owner --no-same-permissions --strip-components=${strip_components} -xpf ${src_target}/${name}.${extension} -C ${target}" + $extract_targz = "tar --no-same-owner ${_same_permissions} --strip-components=${strip_components} -xzf ${src_target}/${name}.${extension} -C ${target}" + $extract_tarbz2 = "tar --no-same-owner ${_same_permissions} --strip-components=${strip_components} -xjf ${src_target}/${name}.${extension} -C ${target}" + $extract_tarxz = "tar --no-same-owner ${_same_permissions} --strip-components=${strip_components} -xpf ${src_target}/${name}.${extension} -C ${target}" $purge_command = $purge ? { true => "rm -rf ${target} && ", diff --git a/manifests/init.pp b/manifests/init.pp index cd32609..ede65a8 100755 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -21,6 +21,7 @@ # - *$strip_components: Default value 0 # - *$proxy_server: Default value undef # - *$user: User used to do the download and the extraction. The final directory will be used by him/her. +# - *$same_permissions: Use permissions from tar archive instead of local umask. # # Example usage: # @@ -49,6 +50,7 @@ $proxy_server=undef, $purge_target=false, $user=undef, + $same_permissions=false, ) { archive::download {"${name}.${extension}": @@ -78,5 +80,6 @@ strip_components => $strip_components, require => Archive::Download["${name}.${extension}"], user => $user, + same_permissions => $same_permissions, } } diff --git a/spec/defines/archive_spec.rb b/spec/defines/archive_spec.rb index b18995a..c8d9f6f 100644 --- a/spec/defines/archive_spec.rb +++ b/spec/defines/archive_spec.rb @@ -29,7 +29,7 @@ :target => '/opt', } end - + it { expect { is_expected.to compile.with_all_deps }.to raise_error(/Must pass url/) } end @@ -67,6 +67,19 @@ it { is_expected.to compile.with_all_deps } end + + context 'with url, target and same_permissions' do + let(:params) do + { + :url => 'http://archive.apache.org/dist/tomcat/tomcat-6/v6.0.26/bin/apache-tomcat-6.0.26.tar.gz', + :target => '/opt', + :same_permissions => true, + } + end + + it { is_expected.to compile.with_all_deps } + end + end end end