The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Ruby, Windows and Pathnames

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Daniel Berger

Posts: 1383
Nickname: djberg96
Registered: Sep, 2004

Daniel Berger is a Ruby Programmer who also dabbles in C and Perl
Ruby, Windows and Pathnames Posted: Sep 8, 2005 12:18 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Daniel Berger.
Original Post: Ruby, Windows and Pathnames
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Daniel Berger
Latest Posts From Testing 1,2,3...

Advertisement
Another lovely path handling issue was discovered today:

irb(main):001:0> path = "C:\\foo\\bar\\baz.rb"
=> "C:\\foo\\bar\\baz.rb"
irb(main):002:0> File.split(path)
=> [".", "C:\\foo\\bar\\baz.rb"]


Naturally, it works properly if I replace the path with "C:/foo/bar/baz.rb". But, you know what? That isn't a valid Windows path, even if Ruby does handle it properly.

The more I think about it, the more I think it was a mistake to make Ruby understand forward slashes in path names on Windows. In what was undoubtedly a "seemed like a good idea at the time" moment, there is simply too much inconsistency with many of the core classes and methods when it comes to native Windows paths.

This becomes especially obvious when one starts mucking about with UNC paths, even when using forward slashes. Consider:
irb(main):005:0> path = "//foo/bar/baz.rb"
=> "//foo/bar/baz.rb"
irb(main):006:0> File.split(path)
=> ["/foo/bar", "baz.rb"]

Technically, that's a bug. The leading double slash should be retained because it's part of the root.

So, how do we keep Ruby cross platform then with regards to paths? The solution I've taken with win32-file is to temporarily replace all forward slashes with backslashes (if present) and use native Windows methods for path handling. Then, if forward slashes were used, the result is given back in that form.

That's a pain, though, and I'm beginning to think the onus of proper pathnames should have been placed on the programmer, rather than trying to Do The Right Thing because, in some cases, the Right Thing doesn't happen anyway.

Read: Ruby, Windows and Pathnames

Topic: Microsoft are pissed about MA switching to OOo Previous Topic   Next Topic Topic: IMG_0766.JPG [Flickr]

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use