Version française
Home     About     Download     Resources     Contact us    
Browse thread
Bug in Filename.basename?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Markus E L <ls-ocaml-2006@m...>
Subject: Re: [Caml-list] Bug in Filename.basename?


Erik de Castro Lopo wrote:

> Richard Jones wrote:
>
>> I think the OCaml one is what I'd reasonably expect actually.
>> 
>> The GNU documentation for basename says:
>> 
>>   `basename' removes any leading directory components from NAME.
>> 
>> and a/b/c/ are leading directory components.
>
> The word "leading" in the above is at best, ambiguous.
>
> Regardless of what the documentation says, the behaviour of Ocaml's
> basename function is different from the basename program (from the
> GNU coreutils package) on my Linux system.
>
> Since I suspect that the basename function is meant to emulate the 
> basename program I see the Ocaml function's behaviour as a bug. I
> would however discount this if the behaviour of basename on some
> other commonly used system (eg *BSD) matched the Ocaml behaviour.
>
> However, here is a comparison chart of what I have tested so far:
>
>                                  "a/b/c"     "a/b/c/"
>     Linux basename                 "c"         "c"
>     Mac OSX basename               "c"         "c"
>     Ocaml Filename.basename        "c"         "."
>
> The behaviour of Ocaml's Filename.basename is the same on Linux and
> Mac OSX.


But

tmp/:$ cat /etc/hosts/
cat: /etc/hosts/: Not a directory

Most shell tools interpret the trailing slash as meaning '[...]/.' .
I'd definitely vote for Linux or Mac OS/X shell basename being buggy
rather than ocamls. Trailing shlashes have meaning (actually I think a
trailing slash should result in a "badly formed path error" but this
convention is probably too deeply entrenched now to fight it).

The standards, though:

 http://www.opengroup.org/onlinepubs/009695399/utilities/basename.html

 - If there are any trailing slash characters in string, they shall be removed.

 http://www.opengroup.org/onlinepubs/009695399/functions/basename.html

 - The same, but only given by example, not by specification

Given how most shell tools interpret trailing slashes I think it's
rather a problem of the standard to introduce inconsistencies in order
to conform to existing practice. In those cases I consider it better
not to orient towards the standard (and who says that OCaml basename
has to work like POSIX or Single Unix basename?).

Regards -- Markus