views:

307

answers:

2

I'm running into an issue with the portion of the Rails generation script that searches the plugin path for appropriately named files to find generators. On one of my systems, I have Ruby installed in c:\dev\ruby and have my project directory at d:\local\projects

The Ruby Pathname#relative_path_from method (which is called by the Rails generator script) chokes on this configuration when it attempts to find the relative path between c:\ and d:\...

Has anyone run into this situation with relative_path_from and multiple drives on Windows? Is there a workaround for the rails generator script?

Here's a sample from IRB:

>> x = Pathname.new('c:/dev/ruby')
=> #<Pathname:c:/dev/ruby>
>> y = Pathname.new('d:/local/projects')
=> #<Pathname:d:/local/projects>
>> x.relative_path_from(y)
ArgumentError: different prefix: "c:/" and "d:/local/projects"
        from c:/dev/ruby/lib/ruby/1.8/pathname.rb:709:in `relative_path_from'
        from (irb)...

If there's no solution, I could always make sure my Ruby install and project directories are on the same drive, but that would prevent me from ever working off a project directory on a pendrive...

UPDATE: Turns out the issue is related specifically to some modification that the Radiant CMS makes to the Rails configuration variables. This change adds additional plugin directories to the project, some of which can cross drive boundaries. Since the Rails generator code doesn't expect that sort of drive-jumping, the generator breaks on my computer...

A: 

Would there be a way to compute a relative path across two different drives in Windows? I don't know.

You can avoid the problem by mounting your D: drive as a folder on your C: drive, assuming you're using NTFS. If that's not acceptable, you could create a junction from D:\local to C:\local which would let you access D:\local from both D: and C:. Then, running the same script from the C: drive should pose no problems.

Matt Haley
I hadn't even thought of setting up a junction. I already had junction.exe on my system, too...Unfortunately, since the problem was a bit more complex than I realized, simply junctioning the project dir didn't fix the issue, either... Ah, well...
Nathan Fritz
A: 

The problem is this as documented in a ticket at http://redmine.ruby-lang.org/issues/show/1366

On Windows, the case of the drive letter can be either upper case or lower case (eg, "C:" or "c:") on the same machine at the same time in different Command Prompt Windows (see below for details). Dir.pwd will return either lower-case or upper-case for the drive letter (“C:/” or “c:/”) depending on the Command Prompt it is run from. However, FILE always uses lower-case drive letter. This can cause an ArgumentError when comparing Dir.pwd and FILE using Pathname#relative_path_from. This happens with version 1.9.1p0 as well. Pathname#relative_path_from should deal with the case where the case of the argument is different.

I have both my ruby install folder and my project folder on c: drive, but I still get the error. I monkey-patched the following lines in pathname.rb file as shown below marked within two asterisk. Remove the two asterisk when you patch.

  def relative_path_from(base_directory)
    dest_directory = self.cleanpath.to_s.**capitalize!**
    base_directory = base_directory.cleanpath.to_s.**capitalize!**
    ...

It works after the patch. Hope it helps.

rupakg