Detecting Mac OS symbolic links with the Unix module ?
| Newsgroups | gmane.comp.lang.ocaml.beginners |
|---|---|
| Message-ID | <[email protected]> |
On my Mac I have some aliases pointing to a directory (they appear
with a circling arrow on them in the Finder).
I would like to be able to detect them from the Unix module (or any module, come to that .. .).
I tried two things that failed :
If I use the Unix.stat function on it, the file kind is Unix.S_DIR not Unix.S_LNK
(I understand that this is because they are Mac symbolic links not Unix symbolic links).
I thought of defining let has_no_links s=(Unix.readlink(s)=s);;
but unfortunately this does not work as it raises exceptions too often. For reasons
unknown to me, Unix.readlink raises the Unix.EINVAL ("invalid argument") exception on perfectly valid names such as "/Users/".
Even if I improve it a little with
let has_no_links s=try (Unix.readlink(s)=s) with _->false;;
this new function will not do what I want as it will return false on /Users/ for example.
Any help appreciated.