Skip to content

Commit ee2c7bc

Browse files
deivid-rodriguezhsbt
authored andcommitted
[rubygems/rubygems] Allow noop bundle install to work on read-only or protected folders
As long as there's nothing new to install and gems are already there. If not, give a meaningful error about what happened. This was how things already worked until ruby/rubygems@345ec45f5a87, so this commit partially reverts that change. ruby/rubygems@794b0ecb39
1 parent ca46a15 commit ee2c7bc

File tree

4 files changed

+44
-5
lines changed

4 files changed

+44
-5
lines changed

lib/bundler/errors.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,24 @@ def message
193193
status_code(31)
194194
end
195195

196+
class ReadOnlyFileSystemError < PermissionError
197+
def message
198+
"There was an error while trying to #{action} `#{@path}`. " \
199+
"File system is read-only."
200+
end
201+
202+
status_code(42)
203+
end
204+
205+
class OperationNotPermittedError < PermissionError
206+
def message
207+
"There was an error while trying to #{action} `#{@path}`. " \
208+
"Underlying OS system call raised an EPERM error."
209+
end
210+
211+
status_code(43)
212+
end
213+
196214
class GenericSystemCallError < BundlerError
197215
attr_reader :underlying_error
198216

lib/bundler/plugin/index.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def initialize
3131

3232
begin
3333
load_index(global_index_file, true)
34-
rescue GenericSystemCallError
34+
rescue PermissionError
3535
# no need to fail when on a read-only FS, for example
3636
nil
3737
rescue ArgumentError => e

lib/bundler/shared_helpers.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ def filesystem_access(path, action = :write, &block)
115115
raise NoSpaceOnDeviceError.new(path, action)
116116
rescue Errno::ENOTSUP
117117
raise OperationNotSupportedError.new(path, action)
118+
rescue Errno::EPERM
119+
raise OperationNotPermittedError.new(path, action)
120+
rescue Errno::EROFS
121+
raise ReadOnlyFileSystemError.new(path, action)
118122
rescue Errno::EEXIST, Errno::ENOENT
119123
raise
120124
rescue SystemCallError => e

spec/bundler/install/process_lock_spec.rb

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,36 @@
2121
expect(the_bundle).to include_gems "myrack 1.0"
2222
end
2323

24+
context "when creating a lock raises Errno::ENOTSUP" do
25+
before { allow(File).to receive(:open).and_raise(Errno::ENOTSUP) }
26+
27+
it "skips creating the lock file and yields" do
28+
processed = false
29+
Bundler::ProcessLock.lock(default_bundle_path) { processed = true }
30+
31+
expect(processed).to eq true
32+
end
33+
end
34+
2435
context "when creating a lock raises Errno::EPERM" do
2536
before { allow(File).to receive(:open).and_raise(Errno::EPERM) }
2637

27-
it "raises a friendly error" do
28-
expect { Bundler::ProcessLock.lock(default_bundle_path) }.to raise_error(Bundler::GenericSystemCallError)
38+
it "skips creating the lock file and yields" do
39+
processed = false
40+
Bundler::ProcessLock.lock(default_bundle_path) { processed = true }
41+
42+
expect(processed).to eq true
2943
end
3044
end
3145

3246
context "when creating a lock raises Errno::EROFS" do
3347
before { allow(File).to receive(:open).and_raise(Errno::EROFS) }
3448

35-
it "raises a friendly error" do
36-
expect { Bundler::ProcessLock.lock(default_bundle_path) }.to raise_error(Bundler::GenericSystemCallError)
49+
it "skips creating the lock file and yields" do
50+
processed = false
51+
Bundler::ProcessLock.lock(default_bundle_path) { processed = true }
52+
53+
expect(processed).to eq true
3754
end
3855
end
3956
end

0 commit comments

Comments
 (0)