caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] RFC: basename, dirname, PR#4549
@ 2011-12-27 16:29 Damien Doligez
  2011-12-27 17:37 ` Daniel Bünzli
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Damien Doligez @ 2011-12-27 16:29 UTC (permalink / raw)
  To: caml users

Hello,

I would like to get some comments from the OCaml community at large about
the problem raised in http://caml.inria.fr/mantis/view.php?id=4549

In a nutshell, the problem is that our version of basename and dirname
are not exactly the same as the Open Group's definition.

We can easily implement the standard behaviour for basename and dirname,
and it seems desirable, but there is a catch: we will have to change
the specification of the standard library slightly.

Currently, we specify this:

   [concat (dirname name) (basename name)] returns a file name
   which is equivalent to [name]. Moreover, after setting the
   current directory to [dirname name] (with {!Sys.chdir}),
   references to [basename name] (which is a relative file name)
   designate the same file as [name] before the call to {!Sys.chdir}.

With the Open Group basename and dirname, this becomes false for
names that include some trailing slashes, because such slashes
are removed by basename.  This means that a name "foo/bar/"
becomes "foo/bar" when put through
  [concat (dirname name) (basename name)]
and opening "foo/bar" may succeed if it is a file, while
opening "foo/bar/" would fail.

I would like to know if anyone relies on the precise behaviour
documented in the standard library, and for everyone else, would
you prefer the old behaviour or the new (standard) behaviour?

-- Damien


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] RFC: basename, dirname, PR#4549
  2011-12-27 16:29 [Caml-list] RFC: basename, dirname, PR#4549 Damien Doligez
@ 2011-12-27 17:37 ` Daniel Bünzli
  2011-12-27 18:36 ` Markus Mottl
  2011-12-27 19:42 ` Gerd Stolpmann
  2 siblings, 0 replies; 5+ messages in thread
From: Daniel Bünzli @ 2011-12-27 17:37 UTC (permalink / raw)
  To: Damien Doligez; +Cc: caml users

I would prefer the standard one.

Note that it may be sensible to contact unison's developers, they must
have quite some experience in dealing with file paths and their
idiosyncrasies.

Best,

Daniel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] RFC: basename, dirname, PR#4549
  2011-12-27 16:29 [Caml-list] RFC: basename, dirname, PR#4549 Damien Doligez
  2011-12-27 17:37 ` Daniel Bünzli
@ 2011-12-27 18:36 ` Markus Mottl
  2011-12-27 19:42 ` Gerd Stolpmann
  2 siblings, 0 replies; 5+ messages in thread
From: Markus Mottl @ 2011-12-27 18:36 UTC (permalink / raw)
  To: Damien Doligez; +Cc: caml users

Hi,

I think the difference will mostly matter for code only that requires
human input of paths, whether in a prompt or through a configuration
file, and even there it would be rather unlikely to encounter such
paths.  Big deal, users can change their input easily.  Having done my
fair share of path mangling, I guess most applications that generate
paths internally only, e.g. to walk through a directory hierarchy, are
safe.  It would seem highly unusual that anybody added an extra slash
in code accessing files within a program.  I personally prefer
standard conformance.

Regards,
Markus

On Tue, Dec 27, 2011 at 11:29, Damien Doligez <damien.doligez@inria.fr> wrote:
> Hello,
>
> I would like to get some comments from the OCaml community at large about
> the problem raised in http://caml.inria.fr/mantis/view.php?id=4549
>
> In a nutshell, the problem is that our version of basename and dirname
> are not exactly the same as the Open Group's definition.
>
> We can easily implement the standard behaviour for basename and dirname,
> and it seems desirable, but there is a catch: we will have to change
> the specification of the standard library slightly.
>
> Currently, we specify this:
>
>   [concat (dirname name) (basename name)] returns a file name
>   which is equivalent to [name]. Moreover, after setting the
>   current directory to [dirname name] (with {!Sys.chdir}),
>   references to [basename name] (which is a relative file name)
>   designate the same file as [name] before the call to {!Sys.chdir}.
>
> With the Open Group basename and dirname, this becomes false for
> names that include some trailing slashes, because such slashes
> are removed by basename.  This means that a name "foo/bar/"
> becomes "foo/bar" when put through
>  [concat (dirname name) (basename name)]
> and opening "foo/bar" may succeed if it is a file, while
> opening "foo/bar/" would fail.
>
> I would like to know if anyone relies on the precise behaviour
> documented in the standard library, and for everyone else, would
> you prefer the old behaviour or the new (standard) behaviour?
>
> -- Damien
>
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>



-- 
Markus Mottl        http://www.ocaml.info        markus.mottl@gmail.com


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] RFC: basename, dirname, PR#4549
  2011-12-27 16:29 [Caml-list] RFC: basename, dirname, PR#4549 Damien Doligez
  2011-12-27 17:37 ` Daniel Bünzli
  2011-12-27 18:36 ` Markus Mottl
@ 2011-12-27 19:42 ` Gerd Stolpmann
  2011-12-28  4:50   ` Till Varoquaux
  2 siblings, 1 reply; 5+ messages in thread
From: Gerd Stolpmann @ 2011-12-27 19:42 UTC (permalink / raw)
  To: Damien Doligez; +Cc: caml users

Hi,

I've done a lot of system programming in the past years, and I cannot
remember that I had to work around this small incompatibility.

Semantically, the POSIX specs are better, because only directories are
allowed to have trailing slashes, and if you want to get the basename of
"path/" you want the name of the directory in >99% of the cases. The
trailing slash has only the meaning that it is asserted that the path
refers to a directory. And operations like "basename" better ignore such
assertions.

There could be a problematic area, though: URLs. A trailing slash means
here a different resource. I don't know whether anybody is using
basename in this context.

Gerd

Am Dienstag, den 27.12.2011, 17:29 +0100 schrieb Damien Doligez:
> Hello,
> 
> I would like to get some comments from the OCaml community at large about
> the problem raised in http://caml.inria.fr/mantis/view.php?id=4549
> 
> In a nutshell, the problem is that our version of basename and dirname
> are not exactly the same as the Open Group's definition.
> 
> We can easily implement the standard behaviour for basename and dirname,
> and it seems desirable, but there is a catch: we will have to change
> the specification of the standard library slightly.
> 
> Currently, we specify this:
> 
>    [concat (dirname name) (basename name)] returns a file name
>    which is equivalent to [name]. Moreover, after setting the
>    current directory to [dirname name] (with {!Sys.chdir}),
>    references to [basename name] (which is a relative file name)
>    designate the same file as [name] before the call to {!Sys.chdir}.
> 
> With the Open Group basename and dirname, this becomes false for
> names that include some trailing slashes, because such slashes
> are removed by basename.  This means that a name "foo/bar/"
> becomes "foo/bar" when put through
>   [concat (dirname name) (basename name)]
> and opening "foo/bar" may succeed if it is a file, while
> opening "foo/bar/" would fail.
> 
> I would like to know if anyone relies on the precise behaviour
> documented in the standard library, and for everyone else, would
> you prefer the old behaviour or the new (standard) behaviour?
> 
> -- Damien
> 
> 



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] RFC: basename, dirname, PR#4549
  2011-12-27 19:42 ` Gerd Stolpmann
@ 2011-12-28  4:50   ` Till Varoquaux
  0 siblings, 0 replies; 5+ messages in thread
From: Till Varoquaux @ 2011-12-28  4:50 UTC (permalink / raw)
  To: Gerd Stolpmann; +Cc: Damien Doligez, caml users

Like Gerd pointed out the trailing slash handing in Posix semantic is
there because a/b/x and a/b/x/ point to the same file. When combined
with naive (but correct in a POSIX setting) application you can end-up
with multiple // in the middle of a path (In posix pathname resolution
multiple /'s are treated exactly like single slashes). This can
happen:

  let mydir = "/a/b/" in
  let myfile = mydir ^ "/myfile" in

now you have myfile = "/a/b//myfile" and (with current ocaml semantic):

  basename (basename myfile) = "a/b"

This can be solved by using a clever Filename.concat (the one in
janestreet's core strips out all the extra '.' and '/' around the
concatenation point) but should really be solved in basename/filename.

Till

On Tue, Dec 27, 2011 at 2:42 PM, Gerd Stolpmann <info@gerd-stolpmann.de> wrote:
> Hi,
>
> I've done a lot of system programming in the past years, and I cannot
> remember that I had to work around this small incompatibility.
>
> Semantically, the POSIX specs are better, because only directories are
> allowed to have trailing slashes, and if you want to get the basename of
> "path/" you want the name of the directory in >99% of the cases. The
> trailing slash has only the meaning that it is asserted that the path
> refers to a directory. And operations like "basename" better ignore such
> assertions.
>
> There could be a problematic area, though: URLs. A trailing slash means
> here a different resource. I don't know whether anybody is using
> basename in this context.
>
> Gerd
>
> Am Dienstag, den 27.12.2011, 17:29 +0100 schrieb Damien Doligez:
>> Hello,
>>
>> I would like to get some comments from the OCaml community at large about
>> the problem raised in http://caml.inria.fr/mantis/view.php?id=4549
>>
>> In a nutshell, the problem is that our version of basename and dirname
>> are not exactly the same as the Open Group's definition.
>>
>> We can easily implement the standard behaviour for basename and dirname,
>> and it seems desirable, but there is a catch: we will have to change
>> the specification of the standard library slightly.
>>
>> Currently, we specify this:
>>
>>    [concat (dirname name) (basename name)] returns a file name
>>    which is equivalent to [name]. Moreover, after setting the
>>    current directory to [dirname name] (with {!Sys.chdir}),
>>    references to [basename name] (which is a relative file name)
>>    designate the same file as [name] before the call to {!Sys.chdir}.
>>
>> With the Open Group basename and dirname, this becomes false for
>> names that include some trailing slashes, because such slashes
>> are removed by basename.  This means that a name "foo/bar/"
>> becomes "foo/bar" when put through
>>   [concat (dirname name) (basename name)]
>> and opening "foo/bar" may succeed if it is a file, while
>> opening "foo/bar/" would fail.
>>
>> I would like to know if anyone relies on the precise behaviour
>> documented in the standard library, and for everyone else, would
>> you prefer the old behaviour or the new (standard) behaviour?
>>
>> -- Damien
>>
>>
>
>
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-12-28  4:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-27 16:29 [Caml-list] RFC: basename, dirname, PR#4549 Damien Doligez
2011-12-27 17:37 ` Daniel Bünzli
2011-12-27 18:36 ` Markus Mottl
2011-12-27 19:42 ` Gerd Stolpmann
2011-12-28  4:50   ` Till Varoquaux

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).