Skip to content

Commit

Permalink
Merge pull request #254 from opscode-cookbooks/salam/urlspace
Browse files Browse the repository at this point in the history
Allow spaces in windows package sources
  • Loading branch information
Kartik Null Cating-Subramanian committed Jul 30, 2015
2 parents 15768a0 + 8dcec6a commit b0cca9d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
6 changes: 5 additions & 1 deletion .kitchen.yml
Expand Up @@ -45,4 +45,8 @@ suites:
- name: certificate
run_list:
- recipe[windows::default]
- recipe[minimal::certificate]
- recipe[minimal::certificate]
- name: package
run_list:
- recipe[windows::default]
- recipe[minimal::package]
14 changes: 12 additions & 2 deletions libraries/windows_helper.rb
Expand Up @@ -63,13 +63,23 @@ def win_version
@win_version ||= Windows::Version.new
end

# Helper function to properly parse a URI
def as_uri(source)
begin
URI.parse(source)
rescue URI::InvalidURIError
Chef::Log.warn("#{source} was an invalid URI. Trying to escape invalid characters")
URI.parse(URI.escape(source))
end
end

# if a file is local it returns a windows friendly path version
# if a file is remote it caches it locally
def cached_file(source, checksum=nil, windows_path=true)
@installer_file_path ||= begin

if source =~ ::URI::ABS_URI && %w[ftp http https].include?(URI.parse(source).scheme)
uri = ::URI.parse(source)
if source =~ /^(file|ftp|http|https):\/\//
uri = as_uri(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)
Expand Down
10 changes: 10 additions & 0 deletions test/cookbooks/minimal/recipes/package.rb
@@ -0,0 +1,10 @@
remote_file 'C:\\Firefox Setup 5.0.exe' do
source 'http://archive.mozilla.org/pub/mozilla.org/mozilla.org/firefox/releases/5.0/win32/en-US/Firefox%20Setup%205.0.exe'
end

windows_package 'Mozilla Firefox 5.0 (x86 en-US)' do
source 'file:///C:/Firefox Setup 5.0.exe'
options '-ms'
installer_type :custom
action :install
end
11 changes: 11 additions & 0 deletions test/integration/package/pester/minimal.package.Tests.ps1
@@ -0,0 +1,11 @@
$global:progressPreference = 'SilentlyContinue'

describe 'minimal::package' {
context 'minimal_package' {

it "task 'task_for_system' was created" {
Test-Path "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" | Should Be True
}
}
}

0 comments on commit b0cca9d

Please sign in to comment.