Skip to content

Commit

Permalink
Merge pull request #820 from skipkayhil/hm-create-file-perm
Browse files Browse the repository at this point in the history
  • Loading branch information
byroot committed May 10, 2023
2 parents 376e141 + 81f9965 commit c16e7a1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/thor/actions/create_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def invoke!
invoke_with_conflict_check do
require "fileutils"
FileUtils.mkdir_p(File.dirname(destination))
File.open(destination, "wb") { |f| f.write render }
File.open(destination, "wb", config[:perm]) { |f| f.write render }
end
given_destination
end
Expand Down
8 changes: 8 additions & 0 deletions spec/actions/create_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ def silence!
expect(File.exist?(File.join(destination_root, "doc/config.rb"))).to be true
end

it "allows setting file permissions" do
create_file("config/private.key", :perm => 0o600)
invoke!

stat = File.stat(File.join(destination_root, "config/private.key"))
expect(stat.mode.to_s(8)).to eq "100600"
end

it "does not create a file if pretending" do
create_file("doc/config.rb", {}, :pretend => true)
invoke!
Expand Down

0 comments on commit c16e7a1

Please sign in to comment.