diff --git a/lib/thor/actions/create_file.rb b/lib/thor/actions/create_file.rb index fa7b22cb..4886dec6 100644 --- a/lib/thor/actions/create_file.rb +++ b/lib/thor/actions/create_file.rb @@ -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 diff --git a/spec/actions/create_file_spec.rb b/spec/actions/create_file_spec.rb index 1e0c934e..1eae4f1c 100644 --- a/spec/actions/create_file_spec.rb +++ b/spec/actions/create_file_spec.rb @@ -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!