diff options
author | Thom May <thom@chef.io> | 2016-07-05 15:22:32 +0100 |
---|---|---|
committer | Thom May <thom@chef.io> | 2016-07-07 15:23:41 +0100 |
commit | c54428b1928815b752de079cfe7df55a52b09775 (patch) | |
tree | 70dcf0b968f4c38b9845cc9409c00c310ba20f49 /lib/chef | |
parent | 8d88150bb10c40d725d8f0b297fc63763a95db07 (diff) | |
download | chef-c54428b1928815b752de079cfe7df55a52b09775.tar.gz |
Use Mixlib::Archive to extract tarballs
this allows us to be truely cross platform, and also to ignore unsafe
paths and permissions.
Signed-off-by: Thom May <thom@chef.io>
Diffstat (limited to 'lib/chef')
-rw-r--r-- | lib/chef/application/client.rb | 4 | ||||
-rw-r--r-- | lib/chef/application/solo.rb | 4 | ||||
-rw-r--r-- | lib/chef/knife/cookbook_site_install.rb | 13 |
3 files changed, 6 insertions, 15 deletions
diff --git a/lib/chef/application/client.rb b/lib/chef/application/client.rb index 77c86ad559..2a2f70c3a1 100644 --- a/lib/chef/application/client.rb +++ b/lib/chef/application/client.rb @@ -27,6 +27,7 @@ require "chef/handler/error_report" require "chef/workstation_config_loader" require "chef/mixin/shell_out" require "chef-config/mixin/dot_d" +require "mixlib/archive" class Chef::Application::Client < Chef::Application include Chef::Mixin::ShellOut @@ -334,8 +335,7 @@ class Chef::Application::Client < Chef::Application FileUtils.mkdir_p(Chef::Config.chef_repo_path) tarball_path = File.join(Chef::Config.chef_repo_path, "recipes.tgz") fetch_recipe_tarball(Chef::Config[:recipe_url], tarball_path) - result = shell_out!("tar zxvf #{tarball_path} -C #{Chef::Config.chef_repo_path}") - Chef::Log.debug "#{result.stdout}" + Mixlib::Archive.new(tarball_path).extract(Chef::Config.chef_repo_path, perms: false, ignore: /^\.$/) end end diff --git a/lib/chef/application/solo.rb b/lib/chef/application/solo.rb index d2516926c4..a7c4038f4c 100644 --- a/lib/chef/application/solo.rb +++ b/lib/chef/application/solo.rb @@ -29,6 +29,7 @@ require "fileutils" require "chef/mixin/shell_out" require "pathname" require "chef-config/mixin/dot_d" +require "mixlib/archive" class Chef::Application::Solo < Chef::Application include Chef::Mixin::ShellOut @@ -273,8 +274,7 @@ class Chef::Application::Solo < Chef::Application FileUtils.mkdir_p(recipes_path) tarball_path = File.join(recipes_path, "recipes.tgz") fetch_recipe_tarball(Chef::Config[:recipe_url], tarball_path) - result = shell_out!("tar zxvf #{tarball_path} -C #{recipes_path}") - Chef::Log.debug "#{result.stdout}" + Mixlib::Archive.new(tarball_path).extract(Chef::Config.chef_repo_path, perms: false, ignore: /^\.$/) end # json_attribs shuld be fetched after recipe_url tarball is unpacked. diff --git a/lib/chef/knife/cookbook_site_install.rb b/lib/chef/knife/cookbook_site_install.rb index 9a1ac93821..43d015dcc4 100644 --- a/lib/chef/knife/cookbook_site_install.rb +++ b/lib/chef/knife/cookbook_site_install.rb @@ -19,6 +19,7 @@ require "chef/knife" require "chef/exceptions" require "shellwords" +require "mixlib/archive" class Chef class Knife @@ -149,17 +150,7 @@ class Chef def extract_cookbook(upstream_file, version) ui.info("Uncompressing #{@cookbook_name} version #{version}.") - extract_command = "tar zxvf \"#{convert_path upstream_file}\"" - if Chef::Platform.windows? - tar_version = shell_out("tar --version").stdout.tr("\n", " ") - if tar_version =~ /GNU tar/ - Chef::Log.debug("GNU tar detected, adding --force-local") - extract_command << " --force-local" - else - Chef::Log.debug("non-GNU tar detected, not adding --force-local") - end - end - shell_out!(extract_command, :cwd => @install_path) + Mixlib::Archive.new(convert_path(upstream_file)).extract(@install_path, perms: false) end def clear_existing_files(cookbook_path) |