Re: Detecting Mac OS symbolic links with the Unix module ?

"Oliver Bandel [email protected] [ocaml_beginners]" <[email protected]>
Newsgroups gmane.comp.lang.ocaml.beginners
Message-ID <20150925093257.Horde.MJT43qVx3LBb8pUmYoVWLTt@webmail.in-berlin.de>
Hi,

Unix.stat does follow the link.
Look at Unix.lstat to get information about the link itself.


Ciao,
    Oliver



Zitat von "[email protected] [ocaml_beginners]"  
<[email protected]> (24 Sep 2015 23:15:58 -0700)

> 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.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.