[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 https://github.com/rubygems/rubygems/commit/345ec45f5a87, so this commit partially reverts that change. https://github.com/rubygems/rubygems/commit/794b0ecb39
This commit is contained in:
parent
ca46a15991
commit
ee2c7bcae5
@ -193,6 +193,24 @@ module Bundler
|
||||
status_code(31)
|
||||
end
|
||||
|
||||
class ReadOnlyFileSystemError < PermissionError
|
||||
def message
|
||||
"There was an error while trying to #{action} `#{@path}`. " \
|
||||
"File system is read-only."
|
||||
end
|
||||
|
||||
status_code(42)
|
||||
end
|
||||
|
||||
class OperationNotPermittedError < PermissionError
|
||||
def message
|
||||
"There was an error while trying to #{action} `#{@path}`. " \
|
||||
"Underlying OS system call raised an EPERM error."
|
||||
end
|
||||
|
||||
status_code(43)
|
||||
end
|
||||
|
||||
class GenericSystemCallError < BundlerError
|
||||
attr_reader :underlying_error
|
||||
|
||||
|
@ -31,7 +31,7 @@ module Bundler
|
||||
|
||||
begin
|
||||
load_index(global_index_file, true)
|
||||
rescue GenericSystemCallError
|
||||
rescue PermissionError
|
||||
# no need to fail when on a read-only FS, for example
|
||||
nil
|
||||
rescue ArgumentError => e
|
||||
|
@ -115,6 +115,10 @@ module Bundler
|
||||
raise NoSpaceOnDeviceError.new(path, action)
|
||||
rescue Errno::ENOTSUP
|
||||
raise OperationNotSupportedError.new(path, action)
|
||||
rescue Errno::EPERM
|
||||
raise OperationNotPermittedError.new(path, action)
|
||||
rescue Errno::EROFS
|
||||
raise ReadOnlyFileSystemError.new(path, action)
|
||||
rescue Errno::EEXIST, Errno::ENOENT
|
||||
raise
|
||||
rescue SystemCallError => e
|
||||
|
@ -21,19 +21,36 @@ RSpec.describe "process lock spec" do
|
||||
expect(the_bundle).to include_gems "myrack 1.0"
|
||||
end
|
||||
|
||||
context "when creating a lock raises Errno::ENOTSUP" do
|
||||
before { allow(File).to receive(:open).and_raise(Errno::ENOTSUP) }
|
||||
|
||||
it "skips creating the lock file and yields" do
|
||||
processed = false
|
||||
Bundler::ProcessLock.lock(default_bundle_path) { processed = true }
|
||||
|
||||
expect(processed).to eq true
|
||||
end
|
||||
end
|
||||
|
||||
context "when creating a lock raises Errno::EPERM" do
|
||||
before { allow(File).to receive(:open).and_raise(Errno::EPERM) }
|
||||
|
||||
it "raises a friendly error" do
|
||||
expect { Bundler::ProcessLock.lock(default_bundle_path) }.to raise_error(Bundler::GenericSystemCallError)
|
||||
it "skips creating the lock file and yields" do
|
||||
processed = false
|
||||
Bundler::ProcessLock.lock(default_bundle_path) { processed = true }
|
||||
|
||||
expect(processed).to eq true
|
||||
end
|
||||
end
|
||||
|
||||
context "when creating a lock raises Errno::EROFS" do
|
||||
before { allow(File).to receive(:open).and_raise(Errno::EROFS) }
|
||||
|
||||
it "raises a friendly error" do
|
||||
expect { Bundler::ProcessLock.lock(default_bundle_path) }.to raise_error(Bundler::GenericSystemCallError)
|
||||
it "skips creating the lock file and yields" do
|
||||
processed = false
|
||||
Bundler::ProcessLock.lock(default_bundle_path) { processed = true }
|
||||
|
||||
expect(processed).to eq true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user