Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

handle read only filesystem #5385

Closed

Conversation

jlambert121
Copy link

Resolves the issue where bundler errors on startup on a read only filesystem.

Resolves #5371

@segiddins
Copy link
Member

This needs test coverage

@jlambert121
Copy link
Author

@segiddins I'll be honest - I have no idea where to add the coverage for that. It seems like #4951 broke it, but I don't see where that added/changed any coverage around this break to give me an idea of where to add it. Are you able to give me some guidance on it?

@segiddins
Copy link
Member

You could write a unit test in spec/bundler/ or a test in spec/commands/install that chmods the tmpdir to not be writable

@bundlerbot
Copy link
Collaborator

☔ The latest upstream changes (presumably #5363) made this pull request unmergeable. Please resolve the merge conflicts.

@davetron5000
Copy link

@segiddins I'm trying to help @jlambert121 with a test and it's proving incredibly difficult.

The line of code being changed has no test coverage at all. I tried to write the following test to cover the feature as implemented on master:

# in spec/bundler/bundler_spec.rb
    it "should blow up if it can't make a homedir" do
      allow(Dir).to receive(:tmpdir).and_return("/TMP")
      allow(FileTest).to receive(:exist?).with("/TMP/bundler/home").and_return(false)
      expect(FileUtils).to receive(:mkpath).once.ordered.with("/TMP/bundler/home")
      expect(FileUtils).to receive(:mkpath).once.ordered.with("/TMP/bundler/home/USER").and_raise(Errno::EACCES)
      expect {
        Bundler.tmp_home_path("USER", "")
      }.to raise_error("OH NOES")
    end

This copies the existing spec https://github.com/bundler/bundler/blob/master/spec/bundler/bundler_spec.rb#L203 and mocks the mkpath to raise the error I think would be raised.

Then I get this:

     LoadError:
       cannot load such file -- diff/lcs

Nothing is requireing this file that i can find. The gem is definitely installed, but no idea.

Is this something obvious that I can fix? Or can you try adding the test above and seeing what happens for you?

(full stack below)

~/Projects/bundler> rspec -b ./spec/bundler/bundler_spec.rb:212
/Users/davec/Projects/bundler/lib/bundler.rb:178: warning: assigned but unused variable - e
WARN: Unresolved specs during Gem::Specification.reset:
      diff-lcs (< 2.0, >= 1.2.0)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
Run options:
  include {:locations=>{"./spec/bundler/bundler_spec.rb"=>[212]}}
  exclude {:rubygems_master=>true, :git=>"=< 2.10.1", :rubygems=>"=< 2.5.1", :ruby=>"=< 2.3.1", :realworld=>true, :sudo=>true}

Bundler
  #tmp_home_path
    should blow up if it can't make a homedir (FAILED - 1)


Retried examples: 0

Failures:

  1) Bundler#tmp_home_path should blow up if it can't make a homedir
     Failure/Error:
       expect {
         Bundler.tmp_home_path("USER", "", "/foo")
       }.to raise_error("OH NOES")
     
     LoadError:
       cannot load such file -- diff/lcs
     # /Users/davec/.rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
     # /Users/davec/.rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-support-3.5.0/lib/rspec/support/hunk_generator.rb:1:in `<top (required)>'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-support-3.5.0/lib/rspec/support.rb:28:in `require_relative'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-support-3.5.0/lib/rspec/support.rb:28:in `block in <module:Support>'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-support-3.5.0/lib/rspec/support.rb:19:in `block in define_optimized_require_for_rspec'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-support-3.5.0/lib/rspec/support/differ.rb:2:in `<top (required)>'
     # /Users/davec/.rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
     # /Users/davec/.rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-expectations-3.5.0/lib/rspec/expectations/fail_with.rb:6:in `differ'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-expectations-3.5.0/lib/rspec/expectations/fail_with.rb:25:in `fail_with'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-expectations-3.5.0/lib/rspec/expectations/handler.rb:40:in `handle_failure'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-expectations-3.5.0/lib/rspec/expectations/handler.rb:50:in `block in handle_matcher'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-expectations-3.5.0/lib/rspec/expectations/handler.rb:27:in `with_matcher'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-expectations-3.5.0/lib/rspec/expectations/handler.rb:48:in `handle_matcher'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-expectations-3.5.0/lib/rspec/expectations/expectation_target.rb:65:in `to'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-expectations-3.5.0/lib/rspec/expectations/expectation_target.rb:101:in `to'
     # ./spec/bundler/bundler_spec.rb:213:in `block (3 levels) in <top (required)>'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:254:in `instance_exec'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:254:in `block in run'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:496:in `block in with_around_and_singleton_context_hooks'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:453:in `block in with_around_example_hooks'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:464:in `block in run'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:602:in `run_around_example_hooks_for'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:464:in `run'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:453:in `with_around_example_hooks'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:496:in `with_around_and_singleton_context_hooks'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:251:in `run'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:627:in `block in run_examples'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:623:in `map'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:623:in `run_examples'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:589:in `run'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:590:in `block in run'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:590:in `map'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:590:in `run'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:113:in `block (3 levels) in run_specs'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:113:in `map'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:113:in `block (2 levels) in run_specs'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:1835:in `with_suite_hooks'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:112:in `block in run_specs'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-core-3.5.4/lib/rspec/core/reporter.rb:77:in `report'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:111:in `run_specs'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:87:in `run'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:71:in `run'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:45:in `invoke'
     # /Users/davec/.gem/ruby/2.3.1/gems/rspec-core-3.5.4/exe/rspec:4:in `<top (required)>'
     # /Users/davec/.gem/ruby/2.3.1/bin/rspec:23:in `load'
     # /Users/davec/.gem/ruby/2.3.1/bin/rspec:23:in `<main>'

Finished in 0.70739 seconds (files took 0.32427 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/bundler/bundler_spec.rb:212 # Bundler#tmp_home_path should blow up if it can't make a homedir

@segiddins
Copy link
Member

rspec requires it to show a diff when tests fail

@davetron5000
Copy link

davetron5000 commented Feb 10, 2017

any ideas on how I can get it to successfully require? If I put require 'diff/lcs' in the spec file, it immediately fails with a LoadError. If i start irb and require it, it works.

@segiddins
Copy link
Member

segiddins commented Feb 10, 2017

Have you run bin/rake spec:deps? are you invoking rspec with bin/rspec?

@davetron5000
Copy link

ok, that worked. thanks!

@segiddins
Copy link
Member

I actually have a fix for this that is more along the lines of what I was thinking in #5371 (comment) -- just allow skipping reading the global config when creating that temporary directory fails

@segiddins
Copy link
Member

Please have a look at #5421

bundlerbot added a commit that referenced this pull request Feb 15, 2017
…indirect

Don't read global settings on a read-only FS with no $HOME

Closes #5371
This is an alternative to #5385
@bundlerbot
Copy link
Collaborator

☔ The latest upstream changes (presumably #5421) made this pull request unmergeable. Please resolve the merge conflicts.

segiddins pushed a commit that referenced this pull request Feb 22, 2017
…indirect

Don't read global settings on a read-only FS with no $HOME

Closes #5371
This is an alternative to #5385

(cherry picked from commit 42b1e1b)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants