[Haskell-cafe] Path names (again?)

Vincenzo aka Nick Name vincenzo_mlRE.MOVE at yahoo.it
Thu Feb 5 22:44:42 EST 2004

Alle 19:13, giovedì 5 febbraio 2004, Glynn Clements ha scritto:
> > - concatenate file paths
>         (concat . intersperse "/")
> Maybe you wanted something more, e.g. canonicalisation?

Yes, maybe an interface to realpath(3) is what I really need.

> > - tell if a path is absolute or relative
>         ((== '/') . head)

Agreed :)

> > - chase symlinks
> I was going to ask what you meant here but, AFAICT, Haskell (at
> least, GHC 5.04) doesn't appear to recognise the existence of
> symlinks. So, whatever you meant, the answer is probably "no".

I currently use module System.Posix from ghc6, there are stat and lstat 
equivalents, what I want is to get the true file pointed from a symlink 
after having known that it is a symlink, this can be done with 
recursion of course, and it's trivial; I was just wondering if it was 
implemented somewhere else, because I am not so expert in working with 
filesystems and could make some mistake (e.g: I realized only recently 
that using an hashtable of already visited files is necessary to avoid 
ciclic links; also, without getting the canonical path, I could visit a 
file twice).

> > - find all the files in a directory (yes, that's what I need :))
> Define "file" (e.g. "regular file", "anything other than a
> directory", "directory entry" etc). Also, define "in"; i.e. are you
> talking about a recursive search (like "find")?

Yes, I forgot to say "recursively". I have an ocaml implementation but 
it's prone to errors because of missing "canonicalization", so I did 
not want to translate that in haskell for the same problem. Currently I 
workarounded this all by forking "find", but it's prone to errors too 
because I have no way to distinguish between newlines ending a file 
name and newlines in the middle of a file name. I should put something 
like "///" with "find -printf" at the end of each file name, and then 
parse that, but it would really be preferable to code an haskell 
library function equivalent to unix find.

> Recursion is a somewhat harder (maybe even impossible), given that
> doesDirectoryExist doesn't distinguish between a directory and a
> symlink to a directory, and the Posix module doesn't appear to
> include anything which would be of use (e.g. a binding for lstat()).

Yes, the System.Posix module in ghc6 has more features, but I still 
don't like to handcode functions like "realpath"; if there is nothing 
else maybe the best thing is to write a binding to this function (I 
never did that but guess it's a one-liner), and to carefully read 
source code for gnu find and implement it in haskell the same way.


Teatri vuoti e inutili potrebbero affollarsi
se tu ti proponessi di recitare te

More information about the Haskell-Cafe mailing list