Skip to content

Commit

Permalink
Merge pull request #152 from buri17/use_full_path_for_windows_commmands
Browse files Browse the repository at this point in the history
Use fullpath for xcopy and icacls.
  • Loading branch information
tas50 committed May 29, 2016
2 parents 87ed3dd + 4363942 commit 724d902
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion libraries/sevenzip_command_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def sevenzip_command
currdir += "\\%#{count}"
end

cmd += "xcopy \"#{currdir}\" \"#{resource.home_dir}\" /s /e"
cmd += "#{ENV.fetch('SystemRoot')}\\System32\\xcopy \"#{currdir}\" \"#{resource.home_dir}\" /s /e"
end
# rubocop:enable Metrics/AbcSize

Expand Down
2 changes: 1 addition & 1 deletion libraries/windows_owner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def initialize(resource)
attr_reader :resource

def command
"icacls \"#{resource.path}\\*\" /setowner \"#{resource.owner}\""
"#{ENV.fetch('SystemRoot')}\\System32\\icacls \"#{resource.path}\\*\" /setowner \"#{resource.owner}\""
end
end
end
4 changes: 3 additions & 1 deletion spec/libraries/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
describe_helpers Ark::ProviderHelpers do
before(:each) do
allow_any_instance_of(Ark::ResourceDefaults).to receive(:file_cache_path).and_return('/var/chef/cache')
allow(ENV).to receive(:fetch).and_call_original
allow(ENV).to receive(:fetch).with('SystemRoot').and_return('C:\\Windows')
end

describe '#owner_command' do
Expand All @@ -12,7 +14,7 @@
with_node_attributes(platform_family: 'windows')
with_resource_properties(owner: 'Bobo', path: 'C:\\temp')

expect(owner_command).to eq('icacls "C:\\temp\\*" /setowner "Bobo"')
expect(owner_command).to eq('C:\\Windows\\System32\\icacls "C:\\temp\\*" /setowner "Bobo"')
end
end

Expand Down
4 changes: 3 additions & 1 deletion spec/libraries/sevenzip_command_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@

before(:each) do
allow(subject).to receive(:sevenzip_binary) { '"C:\\Program Files\\7-zip\\7z.exe"' }
allow(ENV).to receive(:fetch).and_call_original
allow(ENV).to receive(:fetch).with('SystemRoot').and_return('c:\\Windows')
end

describe '#unpack' do
it 'generates the correct command' do
allow(subject).to receive(:make_temp_directory) { 'temp_directory' }
expected_command = "\"C:\\Program Files\\7-zip\\7z.exe\" e \"release_file\" -so | \"C:\\Program Files\\7-zip\\7z.exe\" x -aoa -si -ttar -o\"temp_directory\" -uy && for /f %1 in ('dir /ad /b \"temp_directory\"') do xcopy \"temp_directory\\%1\" \"home_dir\" /s /e"
expected_command = "\"C:\\Program Files\\7-zip\\7z.exe\" e \"release_file\" -so | \"C:\\Program Files\\7-zip\\7z.exe\" x -aoa -si -ttar -o\"temp_directory\" -uy && for /f %1 in ('dir /ad /b \"temp_directory\"') do c:\\Windows\\System32\\xcopy \"temp_directory\\%1\" \"home_dir\" /s /e"
expect(subject.unpack).to eq(expected_command)
end
end
Expand Down
7 changes: 6 additions & 1 deletion spec/libraries/windows_owner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@

let(:resource) { double(path: 'c:\\resource with spaces\\path', owner: 'the new owner') }

before(:each) do
allow(ENV).to receive(:fetch).and_call_original
allow(ENV).to receive(:fetch).with('SystemRoot').and_return('C:\\Windows')
end

it 'generates the correct command for windows file ownership' do
expect(subject.command).to eq('icacls "c:\\resource with spaces\\path\\*" /setowner "the new owner"')
expect(subject.command).to eq('C:\\Windows\\System32\\icacls "c:\\resource with spaces\\path\\*" /setowner "the new owner"')
end
end
5 changes: 5 additions & 0 deletions spec/resources/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@
describe 'install on windows' do
let(:example_recipe) { 'ark_spec::install_windows' }

before(:each) do
allow(ENV).to receive(:fetch).and_call_original
allow(ENV).to receive(:fetch).with('SystemRoot').and_return('C:\\Windows')
end

def node_attributes
{ platform: 'windows', version: '2008R2' }
end
Expand Down

0 comments on commit 724d902

Please sign in to comment.