Skip to content

Commit 328e083

Browse files
author
Nuo Yan
committed
fixed CHEF-216
1 parent 701e2ae commit 328e083

5 files changed

Lines changed: 35 additions & 4 deletions

File tree

chef/lib/chef/mixin/command.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@ def popen4(cmd, args={}, &b)
228228
ENV[key] = value
229229
end
230230
end
231+
232+
if args[:umask]
233+
umask = ((args[:umask].respond_to?(:oct) ? args[:umask].oct : args[:umask].to_i) & 007777)
234+
File.umask(umask)
235+
end
231236

232237
begin
233238
if cmd.kind_of?(Array)

chef/lib/chef/provider/execute.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def action_run
4444
command_args[:user] = @new_resource.user if @new_resource.user
4545
command_args[:group] = @new_resource.group if @new_resource.group
4646
command_args[:cwd] = @new_resource.cwd if @new_resource.cwd
47+
command_args[:umask] = @new_resource.umask if @new_resource.umask
4748

4849
status = run_command(command_args)
4950
if status
@@ -54,4 +55,4 @@ def action_run
5455

5556
end
5657
end
57-
end
58+
end

chef/lib/chef/resource/execute.rb

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,25 @@ def initialize(name, collection=nil, node=nil)
3737
@timeout = nil
3838
@user = nil
3939
@allowed_actions.push(:run)
40+
@umask = nil
4041
end
41-
42+
43+
def umask(arg=nil)
44+
set_or_return(
45+
:umask,
46+
arg,
47+
:kind_of => [ String, Integer ]
48+
)
49+
end
50+
4251
def command(arg=nil)
4352
set_or_return(
4453
:command,
4554
arg,
4655
:kind_of => [ String ]
4756
)
4857
end
49-
58+
5059
def creates(arg=nil)
5160
set_or_return(
5261
:creates,
@@ -111,6 +120,8 @@ def user(arg=nil)
111120
)
112121
end
113122

123+
124+
114125
end
115126
end
116-
end
127+
end

features/execute_commands.feature

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ Feature: Execute Commands
99
When I run the chef-client
1010
Then the run should exit '0'
1111
And a file named 'mastodon_rocks' should exist
12+
13+
Scenario: Execute a command with umask value 777
14+
Given a validated node
15+
And it includes the recipe 'execute_commands::umask'
16+
When I run the chef-client
17+
Then the run should exit '0'
18+
And '/mastodon_rocks_umask' should exist and raise error when copying
1219

1320
Scenario: Execute a command with more than 4k of output
1421
Given a validated node

features/steps/files.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@
4444
File.exists?(File.join(tmpdir, filename)).should be(false)
4545
end
4646

47+
#currently using absolute path (specified in recipe execute_commands/recipes/umask.rb)
48+
Then /^'(.+)' should exist and raise error when copying$/ do |filename|
49+
File.exists?(filename).should be(true)
50+
lambda{copy(filename, filename + "_copy", false)}.should raise_error()
51+
end
52+
53+
4754
Then /^the (.)time of '(.+)' should be different$/ do |time_type, filename|
4855
case time_type
4956
when "m"

0 commit comments

Comments
 (0)