Changes to the semantics of basename/dirname?

There are some issues with the way that File.basename and
File.dirname work, at least on Windows. I also have an issue with
File.expand_path related to some of the issues of File.basename and
File.dirname. This may be present in more than just these, but these
are what I've seen over the past few weeks.

The first problem is that basename, dirname, and expand_path convert
\\ to /. This shouldn't be problematic in the general case (where
the path is then used in a Ruby command), but it would be useful to
indicate that conversion should not be done.

      # Current, invalid behaviour
    p = "a\\b\\c\\d.txt"
  basename(p) #=> "d.txt"
    p1 = dirname(p) #=> "a/b/c" (should be "a\\b\\c")
  basename(p1) #=> "c"
    p2 = dirname(p1) #=> "a/b" (should be "a\\b")
  basename(p2) #=> "b"
    p3 = dirname(p2) #=> "a"
  basename(p3) #=> "a"
    p4 = dirname(p3) #=> "."
  basename(p4) #=> "."
  dirname(p4) #=> "."

    p = "\\a\\b\\c\\d.txt"
  basename(p) #=> "d.txt"
    p1 = dirname(p) #=> "/a/b/c" (should be "\\a\\b\\c")
  basename(p1) #=> "c"
    p2 = dirname(p1) #=> "/a/b" (should be "\\a\\b")
  basename(p2) #=> "b"
    p3 = dirname(p2) #=> "/a" (should be "\\a")
  basename(p3) #=> "a"
    p4 = dirname(p3) #=> "/" (should be "\\")
  basename(p4) #=> "/" (should be "\\")
  dirname(p4) #=> "/" (should be "\\")

The second has to do with UNC/SMB share names.

  p = "\\\\host\\a\\b\\c\\d.txt"
      basename(p) #=> "d.txt"
  p1 = dirname(p) #=> "\\\\host\\a\\b\\c"
      basename(p1) #=> "c"
  p2 = dirname(p1) #=> "\\\\host\\a\\b"
      basename(p2) #=> "b"
  p3 = dirname(p2) #=> "\\\\host\\a"
      basename(p3) #=> "a" (should be "\\\\host\\a")
  p4 = dirname(p3) #=> "\\\\host" (should be "\\\\host\\a")
      basename(p4) #=> "host" (should be "\\\\host\\a")
      dirname(p4) #=> "\\\\" (should be "\\\\host\\a")

In this specification, the base directory (the "device", if you
will), is \\host\a, not \\ or \\host. Just as basename can never go
above "/" in Unix, it should never go above \\hostname\sharename on
Windows UNC shares.

I'm not sure if URI special cases should be built in, but
ftp://ruby-lang.org/pub/ruby would ultimately become "ftp:", which
isn't desired -- but if it doesn't do that, then NetWare device
support ("SYS1:\a\b\c\d.txt") would probably break.

-austin

···

--
Austin Ziegler * halostatue@gmail.com
               * Alternate: austin@halostatue.ca

"Austin Ziegler" <halostatue@gmail.com> schrieb im Newsbeitrag
news:9e7db91104080907595ed3fe0b@mail.gmail.com...

There are some issues with the way that File.basename and
File.dirname work, at least on Windows. I also have an issue with
File.expand_path related to some of the issues of File.basename and
File.dirname. This may be present in more than just these, but these
are what I've seen over the past few weeks.

The first problem is that basename, dirname, and expand_path convert
\\ to /. This shouldn't be problematic in the general case (where
the path is then used in a Ruby command), but it would be useful to
indicate that conversion should not be done.

What Ruby are you using? AFAIK windows compiled Ruby handles that according
to Win conventions. Cygwin ruby handles it according to *nix style. But
then there is cygpath...

Regards

    robert

irb(main):003:0> [RUBY_PLATFORM, RUBY_VERSION, RUBY_RELEASE_DATE].join(" ")
=> "i386-mswin32 1.8.2 2004-07-29"

Ruby converts \ to / and doesn't handle UNC names well at all.

-austin

···

On Tue, 10 Aug 2004 04:21:17 +0900, Robert Klemme <bob.news@gmx.net> wrote:

"Austin Ziegler" <halostatue@gmail.com> schrieb im Newsbeitrag
news:9e7db91104080907595ed3fe0b@mail.gmail.com...
> The first problem is that basename, dirname, and expand_path convert
> \\ to /. This shouldn't be problematic in the general case (where
> the path is then used in a Ruby command), but it would be useful to
> indicate that conversion should not be done.
What Ruby are you using? AFAIK windows compiled Ruby handles that according
to Win conventions. Cygwin ruby handles it according to *nix style. But
then there is cygpath...

--
Austin Ziegler * halostatue@gmail.com
               * Alternate: austin@halostatue.ca

"Austin Ziegler" <halostatue@gmail.com> schrieb im Newsbeitrag
news:9e7db91104080912383403be73@mail.gmail.com...

> "Austin Ziegler" <halostatue@gmail.com> schrieb im Newsbeitrag
> news:9e7db91104080907595ed3fe0b@mail.gmail.com...
> > The first problem is that basename, dirname, and expand_path convert
> > \\ to /. This shouldn't be problematic in the general case (where
> > the path is then used in a Ruby command), but it would be useful to
> > indicate that conversion should not be done.
> What Ruby are you using? AFAIK windows compiled Ruby handles that

according

> to Win conventions. Cygwin ruby handles it according to *nix style.

But

> then there is cygpath...

irb(main):003:0> [RUBY_PLATFORM, RUBY_VERSION, RUBY_RELEASE_DATE].join("

")

=> "i386-mswin32 1.8.2 2004-07-29"

Ruby converts \ to / and doesn't handle UNC names well at all.

Darn! I was sure my old 1.6.8 did at least handle "\"... Maybe it has
changed or my memory fooled me. Sorry for the noise.

Regards

    robert

···

On Tue, 10 Aug 2004 04:21:17 +0900, Robert Klemme <bob.news@gmx.net> wrote: