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

Bundler fails on Dir.chdir when running inside jar on JRuby #1865

Closed
tomtaylor opened this issue Apr 23, 2012 · 11 comments
Closed

Bundler fails on Dir.chdir when running inside jar on JRuby #1865

tomtaylor opened this issue Apr 23, 2012 · 11 comments

Comments

@tomtaylor
Copy link

Bundler 1.1.3 fails when running from inside a packaged jar file, on JRuby. It tries to execute Dir.chdir (Line 273 in bundler.rb), but because that's not a real directory on disk, only inside the JAR file, the OS call to move to that dir fails.

Is there another approach to this that would work inside a JAR?

Errno::ENOTDIR: Not a directory - file:/Users/tom/projects/src/dennis/dennis.jar!/bundler/gems/msgpack-jruby-22e0fa73e437
            chdir at org/jruby/RubyDir.java:448
     load_gemspec at file:/Users/tom/projects/src/dennis/dennis.jar!/gems/bundler-1.1.3/lib/bundler.rb:273
  load_spec_files at file:/Users/tom/projects/src/dennis/dennis.jar!/gems/bundler-1.1.3/lib/bundler/source.rb:340
             each at org/jruby/RubyArray.java:1615
  load_spec_files at file:/Users/tom/projects/src/dennis/dennis.jar!/gems/bundler-1.1.3/lib/bundler/source.rb:339
  load_spec_files at file:/Users/tom/projects/src/dennis/dennis.jar!/gems/bundler-1.1.3/lib/bundler/source.rb:572
      local_specs at file:/Users/tom/projects/src/dennis/dennis.jar!/gems/bundler-1.1.3/lib/bundler/source.rb:372
            specs at file:/Users/tom/projects/src/dennis/dennis.jar!/gems/bundler-1.1.3/lib/bundler/source.rb:557
  __materialize__ at file:/Users/tom/projects/src/dennis/dennis.jar!/gems/bundler-1.1.3/lib/bundler/lazy_specification.rb:53
      materialize at file:/Users/tom/projects/src/dennis/dennis.jar!/gems/bundler-1.1.3/lib/bundler/spec_set.rb:86
             map! at org/jruby/RubyArray.java:2371
      materialize at file:/Users/tom/projects/src/dennis/dennis.jar!/gems/bundler-1.1.3/lib/bundler/spec_set.rb:83
            specs at file:/Users/tom/projects/src/dennis/dennis.jar!/gems/bundler-1.1.3/lib/bundler/definition.rb:127
        specs_for at file:/Users/tom/projects/src/dennis/dennis.jar!/gems/bundler-1.1.3/lib/bundler/definition.rb:172
  requested_specs at file:/Users/tom/projects/src/dennis/dennis.jar!/gems/bundler-1.1.3/lib/bundler/definition.rb:161
  requested_specs at file:/Users/tom/projects/src/dennis/dennis.jar!/gems/bundler-1.1.3/lib/bundler/environment.rb:23
            setup at file:/Users/tom/projects/src/dennis/dennis.jar!/gems/bundler-1.1.3/lib/bundler/runtime.rb:11
            setup at file:/Users/tom/projects/src/dennis/dennis.jar!/gems/bundler-1.1.3/lib/bundler.rb:107
           (root) at file:/Users/tom/projects/src/dennis/dennis.jar!/gems/bundler-1.1.3/lib/bundler/setup.rb:7
          require at org/jruby/RubyKernel.java:1033
          require at file:/Users/tom/projects/src/dennis/dennis.jar!/gems/bundler-1.1.3/lib/bundler/setup.rb:59
           (root) at file:/Users/tom/projects/src/dennis/dennis.jar!/dennis/bin/dennis.rb:16
             load at org/jruby/RubyKernel.java:1058
           (root) at file:/Users/tom/projects/src/dennis/dennis.jar!/dennis/bin/dennis.rb:1
          require at org/jruby/RubyKernel.java:1033
          require at file:/Users/tom/projects/src/dennis/dennis.jar!/META-INF/main.rb:36
           (root) at <script>:3
@josephholsten
Copy link

+1

2 similar comments
@jgnagy
Copy link

jgnagy commented Apr 26, 2012

+1

@masterkain
Copy link

+1

@auser
Copy link

auser commented Dec 13, 2012

+1 any fix on this?

@indirect
Copy link
Member

I don't use JRuby, and I honestly have no idea how to reproduce this, let alone fix it. If you want a fix, please either write one or provide detailed reproduction steps that mean even someone who doesn't use JRuby (like me) can reproduce the problem. The list in ISSUES might help, if you're not sure what to include.

@prandazzo
Copy link

+1

@prandazzo
Copy link

I'have a similar error, anyone have suggestions?

@indirect
Copy link
Member

@prandazzo please see my last comment.

@svenfuchs
Copy link
Contributor

Just ran into this, too.

@indirect the scenario is a jruby application that has been packaged up as a jar file (e.g. with warbler).

It seems to me that bundler tries to chdir into the gem directory so it can eval the gemspec within there: https://github.com/bundler/bundler/blob/master/lib/bundler.rb#L341

Running on jruby within a jar this will fail:

pry(main)> File.directory?('file:/path/to/some.jar!/gems')
=> true
pry(main)> Dir.chdir('file:/path/to/some.jar!/gems')
Errno::ENOTDIR: Not a directory - file:/path/to/some.jar!/gems
from org/jruby/RubyDir.java:458:in `chdir'

I'm not sure if that's not a jruby bug?

@indirect
Copy link
Member

@svenfuchs I guess Bundler could fall back to evaluating the gemspec without changing the current directory if the gemspec isn't in a directory? Would that solve this?

@prandazzo
Copy link

Hi,
I had the same problem and I realized that is impossible to chdir in .jar file.
I packaged a rails app in a single jar (without extracting it) and I had to modify some rails core to get my application working (it's just an experiment). By the way, to avoid this kind of problems, warbler extracts itself to a temp directory before executing.

it's not a jruby bug. I think would be possible to "simulate" chdir in jar file by redefining File class.. but it's very tricky.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants