summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2015-02-27 16:30:39 -0800
committerJay Mundrawala <jdmundrawala@gmail.com>2015-02-27 16:30:39 -0800
commit53da742fbf196bd074411cdf7e6400e6e856119b (patch)
tree18cb17e55279a52453ea8a60dde8882a68d7d4a6
parentc2dfb56e730214266ae07a57a56e5889b1e6b85b (diff)
downloadchef-53da742fbf196bd074411cdf7e6400e6e856119b.tar.gz
Refactor tar_cmd
-rw-r--r--lib/chef/knife/cookbook_site_share.rb22
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/chef/knife/cookbook_site_share.rb b/lib/chef/knife/cookbook_site_share.rb
index 560e0669c1..64bc639a06 100644
--- a/lib/chef/knife/cookbook_site_share.rb
+++ b/lib/chef/knife/cookbook_site_share.rb
@@ -50,6 +50,20 @@ class Chef
:default => false,
:description => "Don't take action, only print what files will be upload to SuperMarket."
+ def tar_cmd
+ if !@tar_cmd
+ @tar_cmd = "tar"
+ begin
+ # Unix and Mac only - prefer gnutar
+ if shell_out("which gnutar").exitstatus.equal?(0)
+ @tar_cmd = "gnutar"
+ end
+ rescue Errno::ENOENT
+ end
+ end
+ @tar_cmd
+ end
+
def run
config[:cookbook_path] ||= Chef::Config[:cookbook_path]
@@ -73,14 +87,6 @@ class Chef
begin
Chef::Log.debug("Temp cookbook directory is #{tmp_cookbook_dir.inspect}")
ui.info("Making tarball #{cookbook_name}.tgz")
- tar_cmd = "tar"
- begin
- # Unix and Mac only - prefer gnutar
- if shell_out("which gnutar").exitstatus.equal?(0)
- tar_cmd = "gnutar"
- end
- rescue Errno::ENOENT
- end
shell_out!("#{tar_cmd} -czf #{cookbook_name}.tgz #{cookbook_name}", :cwd => tmp_cookbook_dir)
rescue => e
ui.error("Error making tarball #{cookbook_name}.tgz: #{e.message}. Increase log verbosity (-VV) for more information.")