Skip to content

Commit

Permalink
Merge pull request #5947 from heyvito/fix/bundler-init-perms
Browse files Browse the repository at this point in the history
Fix `bundle init` not respecting umask in generated gem's Gemfile
  • Loading branch information
deivid-rodriguez committed Oct 3, 2022
2 parents 12e565a + 839a068 commit 7e9afc4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
6 changes: 5 additions & 1 deletion bundler/lib/bundler/cli/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ def run
file << spec.to_gemfile
end
else
FileUtils.cp(File.expand_path("../templates/#{gemfile}", __dir__), gemfile)
File.open(File.expand_path("../templates/#{gemfile}", __dir__), "r") do |template|
File.open(gemfile, "wb") do |destination|
IO.copy_stream(template, destination)
end
end
end

puts "Writing new #{gemfile} to #{SharedHelpers.pwd}/#{gemfile}"
Expand Down
23 changes: 23 additions & 0 deletions bundler/spec/commands/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,29 @@
expect(bundled_app_gemfile).to be_file
end

context "with a template with permission flags not matching current process umask" do
let(:template_file) do
gemfile = Bundler.preferred_gemfile_name
templates_dir.join(gemfile)
end

let(:target_dir) { bundled_app("init_permissions_test") }

around do |example|
old_chmod = File.stat(template_file).mode
FileUtils.chmod(old_chmod | 0o111, template_file) # chmod +x
example.run
FileUtils.chmod(old_chmod, template_file)
end

it "honours the current process umask when generating from a template" do
FileUtils.mkdir(target_dir)
bundle :init, :dir => target_dir
generated_mode = File.stat(File.join(target_dir, "Gemfile")).mode & 0o111
expect(generated_mode).to be_zero
end
end

context "when a Gemfile already exists" do
before do
create_file "Gemfile", <<-G
Expand Down
4 changes: 4 additions & 0 deletions bundler/spec/support/path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ def tool_dir
source_root.join("tool/bundler")
end

def templates_dir
lib_dir.join("bundler", "templates")
end

extend self
end
end

0 comments on commit 7e9afc4

Please sign in to comment.