Skip to content

Commit

Permalink
Merge pull request rubygems#7794 from rubygems/deivid-rodriguez/anoth…
Browse files Browse the repository at this point in the history
…er-permission-issue

Print a proper error when bin dir does not have writable permission bit
  • Loading branch information
deivid-rodriguez committed Jun 27, 2024
2 parents d024794 + 979cd89 commit aae4ee4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
12 changes: 11 additions & 1 deletion bundler/lib/bundler/rubygems_gem_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,17 @@ def install
spec
end

def pre_install_checks
if Bundler.rubygems.provides?("< 3.5")
def pre_install_checks
super
rescue Gem::FilePermissionError
# Ignore permission checks in RubyGems. Instead, go on, and try to write
# for real. We properly handle permission errors when they happen.
nil
end
end

def ensure_writable_dir(dir)
super
rescue Gem::FilePermissionError
# Ignore permission checks in RubyGems. Instead, go on, and try to write
Expand Down
38 changes: 34 additions & 4 deletions bundler/spec/commands/install_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ def run
end
end

describe "when bundle path does not have write access", :permissions do
describe "when bundle path does not have cd permission", :permissions do
let(:bundle_path) { bundled_app("vendor") }

before do
Expand All @@ -839,7 +839,7 @@ def run
end
end

describe "when bundle gems path does not have write access", :permissions do
describe "when bundle gems path does not have cd permission", :permissions do
let(:gems_path) { bundled_app("vendor/#{Bundler.ruby_scope}/gems") }

before do
Expand Down Expand Up @@ -869,7 +869,7 @@ def run
end
end

describe "when bundle bin dir does not have write access", :permissions do
describe "when bundle bin dir does not have cd permission", :permissions do
let(:bin_dir) { bundled_app("vendor/#{Bundler.ruby_scope}/bin") }

before do
Expand Down Expand Up @@ -899,6 +899,36 @@ def run
end
end

describe "when bundle bin dir does not have write access", :permissions do
let(:bin_dir) { bundled_app("vendor/#{Bundler.ruby_scope}/bin") }

before do
FileUtils.mkdir_p(bin_dir)
gemfile <<-G
source "https://gem.repo1"
gem "myrack"
G
end

it "should display a proper message to explain the problem" do
FileUtils.chmod("-w", bin_dir)
bundle "config set --local path vendor"

begin
bundle :install, raise_on_error: false
ensure
FileUtils.chmod("+w", bin_dir)
end

expect(err).not_to include("ERROR REPORT TEMPLATE")

expect(err).to include(
"There was an error while trying to write to `#{bin_dir}`. " \
"It is likely that you need to grant write permissions for that path."
)
end
end

describe "when bundle extensions path does not have write access", :permissions do
let(:extensions_path) { bundled_app("vendor/#{Bundler.ruby_scope}/extensions/#{Gem::Platform.local}/#{Gem.extension_api_version}") }

Expand Down Expand Up @@ -929,7 +959,7 @@ def run
end
end

describe "when the path of a specific gem is not writable", :permissions do
describe "when the path of a specific gem does not have cd permission", :permissions do
let(:gems_path) { bundled_app("vendor/#{Bundler.ruby_scope}/gems") }
let(:foo_path) { gems_path.join("foo-1.0.0") }

Expand Down

0 comments on commit aae4ee4

Please sign in to comment.