diff options
author | The Bundler Bot <bot@bundler.io> | 2017-09-10 20:25:51 +0000 |
---|---|---|
committer | The Bundler Bot <bot@bundler.io> | 2017-09-10 20:25:51 +0000 |
commit | 4897ee981aabff9b5483edbd42c1be7616183707 (patch) | |
tree | bd6e4c6c02f51484877dfbf9da55b35d6c17fbf2 | |
parent | 3abe35c810183a389934ab8e68f7a890cde0b44f (diff) | |
parent | 932ea905eb1e35552515abf12023b95629b8fd46 (diff) | |
download | bundler-4897ee981aabff9b5483edbd42c1be7616183707.tar.gz |
Auto merge of #5954 - ajwann:check-permissions-for-client-index-dir, r=segiddins
ensure $HOME and Dir.tmpdir are writable
Fixes #5518
### What was the end-user problem that led to this PR?
A user had issues installing gems due to a permissions issue on the temp dir, because
Bundler was not checking for proper permissions on the temp directory or $HOME.
### What was your diagnosis of the problem?
After discussing the issue with @colby-swandale, the solution was to check permissions on $HOME and the ```tmpdir```.
### What is your fix for the problem, implemented in this PR?
The creation of the [temp dir](https://github.com/bundler/bundler/blob/master/lib/bundler/compact_index_client/updater.rb#L31) is now wrapped in the block passed to ```filesystem_access```, so ```filesystem_access``` will rescue the ```Errno::EACCES``` exception which is thrown if the effective user of the bundler process doesn't have sufficient permissions to create the temp dir.
### Why did you choose this fix out of the possible options?
I chose this fix because it's what was discussed in the original issue thread.
-rw-r--r-- | lib/bundler/compact_index_client/updater.rb | 5 | ||||
-rw-r--r-- | spec/bundler/compact_index_client/updater_spec.rb | 14 |
2 files changed, 19 insertions, 0 deletions
diff --git a/lib/bundler/compact_index_client/updater.rb b/lib/bundler/compact_index_client/updater.rb index 6a66fbc3fe..e80574e3ba 100644 --- a/lib/bundler/compact_index_client/updater.rb +++ b/lib/bundler/compact_index_client/updater.rb @@ -78,6 +78,11 @@ module Bundler update(local_path, remote_path, :retrying) end + rescue Errno::EACCES + raise Bundler::PermissionError, + "Bundler does not have write access to create a temp directory " \ + "within #{Dir.tmpdir}. Bundler must have write access to your " \ + "systems temp directory to function properly. " end def etag_for(path) diff --git a/spec/bundler/compact_index_client/updater_spec.rb b/spec/bundler/compact_index_client/updater_spec.rb index 3c4f212b60..af24e58d5f 100644 --- a/spec/bundler/compact_index_client/updater_spec.rb +++ b/spec/bundler/compact_index_client/updater_spec.rb @@ -27,4 +27,18 @@ RSpec.describe Bundler::CompactIndexClient::Updater do end.to raise_error(Bundler::CompactIndexClient::Updater::MisMatchedChecksumError) end end + + context "when bundler doesn't have permissions on Dir.tmpdir" do + let(:response) { double(:response, :body => "") } + let(:local_path) { Pathname("/tmp/localpath") } + let(:remote_path) { double(:remote_path) } + + it "Errno::EACCES is raised" do + allow(Dir).to receive(:mktmpdir) { raise Errno::EACCES } + + expect do + updater.update(local_path, remote_path) + end.to raise_error(Bundler::PermissionError) + end + end end |