JRuby

Can not to create Ruby on rails application while using UNC path folder

Details

  • Type: Bug Bug
  • Status: Open Open
  • Priority: Blocker Blocker
  • Resolution: Unresolved
  • Affects Version/s: JRuby 1.1.2, JRuby 1.6RC1
  • Fix Version/s: None
  • Component/s: HelpWanted, Windows
  • Labels:
    None
  • Environment:
    Windows XP, Netbeans IDE
  • Number of attachments :
    1

Description

I used Netbeans IDE
I've tried to create Ruby on rails application with location in UNC path folder.
IDE hangs after push finish button of create Ruby on rails application dialog.

In Output log I see :
exists
create app/controllers
No such file or directory - No such file or directory - //Sun-rashid/work/.

When I used Ruby 1.8.6-p111 as Ruby platform Ruby on Rails application was successfully created.

Issue Links

Activity

Hide
Vladimir Sizikov added a comment - - edited

Indeed, there is a bug. JRuby's File.dirname can't handle UNC filenames properly:

File.dirname("\\\\fedora") -> "\\"

File.dirname("\\\\fedora\\share") --> "\\\\fedora"

While on MRI:

File.dirname("\\\\fedora") -> "\\\\fedora"

File.dirname("\\\\fedora\\share") --> "\\\\fedora\\share"

Here's a wrong stack of dirnames, used by fileutils constructed under JRUBY;

["\\\\fedora\\opt\\work\\samples\\rails.tmp/app/controllers",
"\\\\fedora\\opt\\work\\samples\\rails.tmp/app",
 "\\\\fedora\\opt\\work\\samples\\rails.tmp",
"\\\\fedora\\opt\\work\\samples",
"\\\\fedora\\opt\\work",
"\\\\fedora\\opt",
"\\\\fedora",
"\\",
"/"]

Here's MRI's results:

["\\\\fedora\\opt\\work\\samples\\rails.tmp/app/controllers",
"\\\\fedora\\opt\\work\\samples\\rails.tmp/app",
 "\\\\fedora\\opt\\work\\samples\\rails.tmp",
"\\\\fedora\\opt\\work\\samples",
"\\\\fedora\\opt\\work",
"\\\\fedora\\opt"]
Show
Vladimir Sizikov added a comment - - edited Indeed, there is a bug. JRuby's File.dirname can't handle UNC filenames properly:
File.dirname("\\\\fedora") -> "\\"

File.dirname("\\\\fedora\\share") --> "\\\\fedora"
While on MRI:
File.dirname("\\\\fedora") -> "\\\\fedora"

File.dirname("\\\\fedora\\share") --> "\\\\fedora\\share"
Here's a wrong stack of dirnames, used by fileutils constructed under JRUBY;
["\\\\fedora\\opt\\work\\samples\\rails.tmp/app/controllers",
"\\\\fedora\\opt\\work\\samples\\rails.tmp/app",
 "\\\\fedora\\opt\\work\\samples\\rails.tmp",
"\\\\fedora\\opt\\work\\samples",
"\\\\fedora\\opt\\work",
"\\\\fedora\\opt",
"\\\\fedora",
"\\",
"/"]
Here's MRI's results:
["\\\\fedora\\opt\\work\\samples\\rails.tmp/app/controllers",
"\\\\fedora\\opt\\work\\samples\\rails.tmp/app",
 "\\\\fedora\\opt\\work\\samples\\rails.tmp",
"\\\\fedora\\opt\\work\\samples",
"\\\\fedora\\opt\\work",
"\\\\fedora\\opt"]
Hide
Charles Oliver Nutter added a comment -

Ugh. Pathing on windows. Help from community is requested

Show
Charles Oliver Nutter added a comment - Ugh. Pathing on windows. Help from community is requested
Hide
Daniel Berger added a comment -

Interesting, this must have been fixed in MRI fairly recently. It didn't always work right, which is why I originally redefined it in win32-file.

Another interesting thing to note is that MRI strips extra slashes in the first part of a root path, both on Windows and Unix. For example:

File.dirname("////foo/bar/baz") # => /foo/bar

Even more fun, it doesn't do this for any other part of the path:

File.dirname("////foo//bar/baz") # => /foo//bar

Why? I'm not entirely sure but it may have been a partial attempt at POSIX compliance which technically permits any number of slashes between paths. Just "cd ////usr///local//bin" to see what I mean. Or maybe it's just a bug in MRI.

Show
Daniel Berger added a comment - Interesting, this must have been fixed in MRI fairly recently. It didn't always work right, which is why I originally redefined it in win32-file. Another interesting thing to note is that MRI strips extra slashes in the first part of a root path, both on Windows and Unix. For example:
File.dirname("////foo/bar/baz") # => /foo/bar
Even more fun, it doesn't do this for any other part of the path:
File.dirname("////foo//bar/baz") # => /foo//bar
Why? I'm not entirely sure but it may have been a partial attempt at POSIX compliance which technically permits any number of slashes between paths. Just "cd ////usr///local//bin" to see what I mean. Or maybe it's just a bug in MRI.
Hide
Hiro Asari added a comment -

Here's an attempt to shoot down this long-standing bug. I used java.util.regex package to solve the problem.

On Windows, you should get something like this:

$ jruby -S irb
irb(main):001:0> File.dirname "\\\\foo\\bar"
=> "//foo/bar"
irb(main):002:0> File.dirname "\\\\foo\\bar\\baz"
=> "//foo/bar/baz"
irb(main):003:0> File.dirname "\\\\foo\\bar\\baz\\"
=> "//foo/bar/baz"
irb(main):004:0> File.dirname "\\\\foo\\"
=> "//foo"
irb(main):005:0> File.dirname "\\\\foo bar\\"
=> "//foo bar"
irb(main):006:0> File.dirname "\\\\foo
irb(main):007:0" bar"
=> "//foo \nbar"

The regular expression may be a little too forgiving. For example, 256.256.31.1 (an invalid "IPv4" address) is allowed in the server portion. (One may argue that error should be picked up somewhere downstream.)

I haven't tested this to create a Rails application, so it may not be a satisfactory solution to the problem after all.

Also, the patch does not address the compression of the slashes that Daniel mentions.

Show
Hiro Asari added a comment - Here's an attempt to shoot down this long-standing bug. I used java.util.regex package to solve the problem. On Windows, you should get something like this:
$ jruby -S irb
irb(main):001:0> File.dirname "\\\\foo\\bar"
=> "//foo/bar"
irb(main):002:0> File.dirname "\\\\foo\\bar\\baz"
=> "//foo/bar/baz"
irb(main):003:0> File.dirname "\\\\foo\\bar\\baz\\"
=> "//foo/bar/baz"
irb(main):004:0> File.dirname "\\\\foo\\"
=> "//foo"
irb(main):005:0> File.dirname "\\\\foo bar\\"
=> "//foo bar"
irb(main):006:0> File.dirname "\\\\foo
irb(main):007:0" bar"
=> "//foo \nbar"
The regular expression may be a little too forgiving. For example, 256.256.31.1 (an invalid "IPv4" address) is allowed in the server portion. (One may argue that error should be picked up somewhere downstream.) I haven't tested this to create a Rails application, so it may not be a satisfactory solution to the problem after all. Also, the patch does not address the compression of the slashes that Daniel mentions.
Hide
Daniel Berger added a comment -

Trailing slashes should not be considered when determining dirname. The 3rd example is incorrect behavior.

Show
Daniel Berger added a comment - Trailing slashes should not be considered when determining dirname. The 3rd example is incorrect behavior.
Hide
Daniel Berger added a comment -

The proper solution IMO is to use JNI + PathRemoveFileSpec().

Show
Daniel Berger added a comment - The proper solution IMO is to use JNI + PathRemoveFileSpec().
Hide
Hiro Asari added a comment -

As noted in JRUBY-5440, this issue still persists in 1.6.0.RC1.

Show
Hiro Asari added a comment - As noted in JRUBY-5440, this issue still persists in 1.6.0.RC1.
Hide
Ahmed Obeidul Majid added a comment -

I have tried to fix File.dirname() function. The results are the same as those you get in Ruby. I assumed Ruby handles UNC pathnames correctly.

Is there someplace where I can see all the different forms UNC path names can take and the correct output for them?

Show
Ahmed Obeidul Majid added a comment - I have tried to fix File.dirname() function. The results are the same as those you get in Ruby. I assumed Ruby handles UNC pathnames correctly. Is there someplace where I can see all the different forms UNC path names can take and the correct output for them?
Hide
Ahmed Obeidul Majid added a comment - - edited

Further, FileUtils seems to be "broken". When you try to do a FileUtils.mkdir(any path), instead of creating a new directory, the irb crashes.

Show
Ahmed Obeidul Majid added a comment - - edited Further, FileUtils seems to be "broken". When you try to do a FileUtils.mkdir(any path), instead of creating a new directory, the irb crashes.
Hide
Charles Oliver Nutter added a comment -

Ahmed: We appreciate your help, but it would be much easier for us to incorporate your changes if you provide them as a patch (using git diff or git format-patch are both fine). That will make it possible for us to apply your changes to a recent version of JRuby, which your raw file doesn't really allow us to do easily.

As for UNC cases, I'm not sure. I do not use Windows anymore. I would guess there's a paper or documentation somewhere on the UNC path format...google around for "unc path specification" and maybe something will come up.

Show
Charles Oliver Nutter added a comment - Ahmed: We appreciate your help, but it would be much easier for us to incorporate your changes if you provide them as a patch (using git diff or git format-patch are both fine). That will make it possible for us to apply your changes to a recent version of JRuby, which your raw file doesn't really allow us to do easily. As for UNC cases, I'm not sure. I do not use Windows anymore. I would guess there's a paper or documentation somewhere on the UNC path format...google around for "unc path specification" and maybe something will come up.
Hide
Ahmed Obeidul Majid added a comment - - edited

The initial implementation was not using UNC path names. It was more like a string manipulation (and it was mentioned that it was incomplete). So I just tweaked the code a bit to make it work properly.

Show
Ahmed Obeidul Majid added a comment - - edited The initial implementation was not using UNC path names. It was more like a string manipulation (and it was mentioned that it was incomplete). So I just tweaked the code a bit to make it work properly.
Hide
Hiro Asari added a comment -

Replacing RubyFile.java with the attached one breaks the file lookup. For example:

$ jruby -S rake spec:short
LoadError: no such file to load -- /Users/asari/Development/src/jruby/lib/ruby/gems/1.8/specifications/rake-0.9.2.2.gemspec/gems/rake-0.9.2.2/bin/rake
    load at org/jruby/RubyKernel.java:986
  (root) at /Users/asari/Development/src/jruby/bin/rake:19

rake-0.9.2.2.gemspec is a file. The patch is appending /gems/rake-0.9.2.2/bin/rake when JRuby looks for a script to load.

Show
Hiro Asari added a comment - Replacing RubyFile.java with the attached one breaks the file lookup. For example:
$ jruby -S rake spec:short
LoadError: no such file to load -- /Users/asari/Development/src/jruby/lib/ruby/gems/1.8/specifications/rake-0.9.2.2.gemspec/gems/rake-0.9.2.2/bin/rake
    load at org/jruby/RubyKernel.java:986
  (root) at /Users/asari/Development/src/jruby/bin/rake:19
rake-0.9.2.2.gemspec is a file. The patch is appending /gems/rake-0.9.2.2/bin/rake when JRuby looks for a script to load.
Hide
Ahmed Obeidul Majid added a comment -

Umm... I am getting: "jruby: No such file or directory – rake (LoadError)" message. That is what the output should be, right?

Show
Ahmed Obeidul Majid added a comment - Umm... I am getting: "jruby: No such file or directory – rake (LoadError)" message. That is what the output should be, right?
Hide
Hiro Asari added a comment -

No, it's not. JRuby should be able to find rake, since we distribute it with JRuby.

Show
Hiro Asari added a comment - No, it's not. JRuby should be able to find rake, since we distribute it with JRuby.
Hide
Ahmed Obeidul Majid added a comment -

I am getting the same result even with the original source code. I get a LoadError. Let me work with it a little bit more to see if my patch is the problem.

Ok, here is what I am doing.. I download the source code from the git repository, run ant in the jruby directory, set my PATH variable to the bin directory. Then I run the jruby -S command and get the LoadError message.

But if I try to use the installation package jruby, JRuby finds rake.

Show
Ahmed Obeidul Majid added a comment - I am getting the same result even with the original source code. I get a LoadError. Let me work with it a little bit more to see if my patch is the problem. Ok, here is what I am doing.. I download the source code from the git repository, run ant in the jruby directory, set my PATH variable to the bin directory. Then I run the jruby -S command and get the LoadError message. But if I try to use the installation package jruby, JRuby finds rake.
Hide
Hiro Asari added a comment -

Please attach (or paste it on https://gist.github.com or pastie, or whatever) what you're doing to get to the LoadError with the current repository.

Show
Hiro Asari added a comment - Please attach (or paste it on https://gist.github.com or pastie, or whatever) what you're doing to get to the LoadError with the current repository.
Hide
Ahmed Obeidul Majid added a comment -

1. Run ant.
2. Go into bin folder.
3. Run jruby -S rake spec:short
And I get the LoadError.

Not sure if that's what you want to know though..

Show
Ahmed Obeidul Majid added a comment - 1. Run ant. 2. Go into bin folder. 3. Run jruby -S rake spec:short And I get the LoadError. Not sure if that's what you want to know though..
Hide
Hiro Asari added a comment -

Ahmed,

You are right. I was under the wrong impression that we had rake under bin, but the master branch doesn't have it on a fresh clone of the repository.

At any rate, you can install rake itself with jruby -S gem install rake (or any of the ant targets that includes install-dev-gems). Also, -Xdebug.scriptResolution=true will show you where the script is found (if any).

Please test your patch. Thank you.

Show
Hiro Asari added a comment - Ahmed, You are right. I was under the wrong impression that we had rake under bin, but the master branch doesn't have it on a fresh clone of the repository. At any rate, you can install rake itself with jruby -S gem install rake (or any of the ant targets that includes install-dev-gems). Also, -Xdebug.scriptResolution=true will show you where the script is found (if any). Please test your patch. Thank you.

People

Vote (1)
Watch (6)

Dates

  • Created:
    Updated: