diff options
author | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-02-12 12:55:58 -0600 |
---|---|---|
committer | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-02-12 12:55:58 -0600 |
commit | a4aeabd9d368e6bc964b8634440ed908076d24e2 (patch) | |
tree | b348ea8d5e72de40a4f5ffdd584d422b212632d1 | |
parent | 2d988447c6f1947512f0dc2c0964c3a9ead19131 (diff) | |
download | chef-jdm/win-package-remote.tar.gz |
Allow windows_package to download target filejdm/win-package-remote
-rw-r--r-- | lib/chef/provider/package/windows.rb | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/lib/chef/provider/package/windows.rb b/lib/chef/provider/package/windows.rb index 143d82f111..2aaddbf036 100644 --- a/lib/chef/provider/package/windows.rb +++ b/lib/chef/provider/package/windows.rb @@ -36,7 +36,7 @@ class Chef # load_current_resource is run in Chef::Provider#run_action when not in whyrun_mode? def load_current_resource - @new_resource.source(Chef::Util::PathHelper.validate_path(@new_resource.source)) + @new_resource.source(cached_file(@new_resource.source)) @current_resource = Chef::Resource::WindowsPackage.new(@new_resource.name) @current_resource.version(package_provider.installed_version) @@ -80,6 +80,28 @@ class Chef def remove_package(name, version) package_provider.remove_package(name, version) end + + def cached_file(source, checksum=nil) + @installer_file_path ||= begin + + file_path = if source =~ ::URI::ABS_URI && %w[ftp http https].include?(URI.parse(source).scheme) + uri = ::URI.parse(source) + cache_file_path = "#{Chef::Config[:file_cache_path]}/#{::File.basename(::URI.unescape(uri.path))}" + Chef::Log.debug("Caching a copy of file #{source} at #{cache_file_path}") + r = Chef::Resource::RemoteFile.new(cache_file_path, run_context) + r.source(source) + r.backup(false) + r.checksum(checksum) if checksum + r.run_action(:create) + cache_file_path + else + source + end + + Chef::Util::PathHelper.validate_path(file_path) + end + end + end end end |