diff options
Diffstat (limited to 'libraries/helper.rb')
-rw-r--r-- | libraries/helper.rb | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/libraries/helper.rb b/libraries/helper.rb new file mode 100644 index 0000000..953213c --- /dev/null +++ b/libraries/helper.rb @@ -0,0 +1,45 @@ +# +# Author:: Seth Chisamore (<schisamo@opscode.com>) +# Cookbook Name:: windows +# Library:: helper +# +# Copyright:: 2011, Opscode, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +module Windows + module Helpers + + def cached_file(source, windows_path=true) + @installer_file_path ||= begin + + if(source =~ /^(https?:\/\/)(.*\/)(.*)$/) + cache_file_path = "#{Chef::Config[:file_cache_path]}/#{::File.basename(source)}" + 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.mode("0755") + r.run_action(:create) + else + cache_file_path = source + end + + cache_file_path.gsub!(::File::SEPARATOR, ::File::ALT_SEPARATOR) if windows_path + cache_file_path + end + end + + end +end
\ No newline at end of file |