Skip to content

Commit b26074a

Browse files
authored
Merge pull request #9557 from maxfelsher-cgi/fix-install-permissions
Do not hard-code permissions for new gem directories during bundle install
2 parents 8052c40 + 06e9021 commit b26074a

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

bundler/lib/bundler/rubygems_gem_installer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def install
2020
strict_rm_rf spec.extension_dir
2121

2222
SharedHelpers.filesystem_access(gem_dir, :create) do
23-
FileUtils.mkdir_p gem_dir, mode: 0o755
23+
FileUtils.mkdir_p gem_dir
2424
end
2525

2626
SharedHelpers.filesystem_access(gem_dir, :write) do

spec/commands/install_spec.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,43 @@ def run
13061306
end
13071307
end
13081308

1309+
describe "when using umask 002 and setgid bit", :permissions do
1310+
let(:gems_path) { bundled_app("vendor/#{Bundler.ruby_scope}/gems") }
1311+
let(:foo_path) { gems_path.join("foo-1.0.0") }
1312+
1313+
before do
1314+
build_repo4 do
1315+
build_gem "foo", "1.0.0" do |s|
1316+
s.write "CHANGELOG.md", "foo"
1317+
end
1318+
end
1319+
1320+
gemfile <<-G
1321+
source "https://gem.repo4"
1322+
gem 'foo'
1323+
G
1324+
1325+
FileUtils.mkdir_p(gems_path)
1326+
FileUtils.chmod("g+s", gems_path)
1327+
end
1328+
1329+
it "should create the gem directory with proper permissions" do
1330+
with_umask(0o002) do
1331+
bundle_config "path vendor"
1332+
bundle :install
1333+
expect(out).to include("Bundle complete!")
1334+
expect(err).to be_empty
1335+
# Linux's SysV-derived mkdir(2) propagates the set-group-ID bit
1336+
# from the parent directory to newly created subdirectories. BSD
1337+
# (including macOS) inherits the parent's group via mkdir(2) but
1338+
# does not copy the set-group-ID bit itself, so the expected
1339+
# mode differs by platform.
1340+
expected = RUBY_PLATFORM.include?("darwin") ? 0o0775 : 0o2775
1341+
expect(File.stat(foo_path).mode & 0o7777).to eq(expected)
1342+
end
1343+
end
1344+
end
1345+
13091346
describe "parallel make" do
13101347
before do
13111348
unless Gem::Installer.private_method_defined?(:build_jobs)

0 commit comments

Comments
 (0)