Skip to content

Commit c16e7a1

Browse files
authored
Merge pull request #820 from skipkayhil/hm-create-file-perm
2 parents 376e141 + 81f9965 commit c16e7a1

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/thor/actions/create_file.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def invoke!
6060
invoke_with_conflict_check do
6161
require "fileutils"
6262
FileUtils.mkdir_p(File.dirname(destination))
63-
File.open(destination, "wb") { |f| f.write render }
63+
File.open(destination, "wb", config[:perm]) { |f| f.write render }
6464
end
6565
given_destination
6666
end

spec/actions/create_file_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ def silence!
3333
expect(File.exist?(File.join(destination_root, "doc/config.rb"))).to be true
3434
end
3535

36+
it "allows setting file permissions" do
37+
create_file("config/private.key", :perm => 0o600)
38+
invoke!
39+
40+
stat = File.stat(File.join(destination_root, "config/private.key"))
41+
expect(stat.mode.to_s(8)).to eq "100600"
42+
end
43+
3644
it "does not create a file if pretending" do
3745
create_file("doc/config.rb", {}, :pretend => true)
3846
invoke!

0 commit comments

Comments
 (0)