mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[rubygems/rubygems] Copy template contents instead of file and perms
This allows the file to be created without copying permissions
from Bundler's installation source. The previous behaviour was
noticed after installing Ruby through brew, and using bundle
init, which yielded a read-only Gemfile.
839a06851d
This commit is contained in:
parent
b7a61cb485
commit
bc6c1e0e25
3 changed files with 32 additions and 1 deletions
|
@ -32,7 +32,11 @@ module Bundler
|
||||||
file << spec.to_gemfile
|
file << spec.to_gemfile
|
||||||
end
|
end
|
||||||
else
|
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
|
end
|
||||||
|
|
||||||
puts "Writing new #{gemfile} to #{SharedHelpers.pwd}/#{gemfile}"
|
puts "Writing new #{gemfile} to #{SharedHelpers.pwd}/#{gemfile}"
|
||||||
|
|
|
@ -7,6 +7,29 @@ RSpec.describe "bundle init" do
|
||||||
expect(bundled_app_gemfile).to be_file
|
expect(bundled_app_gemfile).to be_file
|
||||||
end
|
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
|
context "when a Gemfile already exists" do
|
||||||
before do
|
before do
|
||||||
create_file "Gemfile", <<-G
|
create_file "Gemfile", <<-G
|
||||||
|
|
|
@ -312,6 +312,10 @@ module Spec
|
||||||
source_root.join("tool/bundler")
|
source_root.join("tool/bundler")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def templates_dir
|
||||||
|
lib_dir.join("bundler", "templates")
|
||||||
|
end
|
||||||
|
|
||||||
extend self
|
extend self
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue