From simon.urbanek at r-project.org  Mon Feb 29 16:02:01 2016
From: simon.urbanek at r-project.org (Simon Urbanek)
Date: Mon, 29 Feb 2016 10:02:01 -0500
Subject: [Rd] Sys.readlink (on BSD vs Linux)
In-Reply-To: <37EB35B6-22B9-4072-B874-C67365B89F57@icloud.com>
References: <10D14BD3-2646-4A1C-BA2A-5B93414D2436@icloud.com>
	<56D4211A.8060306@aalto.fi>
	<37EB35B6-22B9-4072-B874-C67365B89F57@icloud.com>
Message-ID: <E6C8E0BD-6BA1-4C18-8264-8FA4B052DDDA@r-project.org>


> On Feb 29, 2016, at 5:59 AM, Sven Templer <sven.templer at gmail.com> wrote:
> 
> Hello,
> 
> sorry for not being clear enough.
> 
> My problem is represented with the following code, running on OSX:
> 
> mkdir ~/test
> ln -s ~/test ~/testlink
> touch ~/test/foo
> Rscript -e 'Sys.readlink(c("~/test/foo", "~/testlink/foo")); normalizePath(c("~/test/foo","~/testlink/foo"))'
> 
> I expected `Sys.readlink` to show the same output as `normalizePath`.


Why? To quote from the Sys.readlink() docs:

Value:

     A character vector of the same length as ?paths?.  The entries are
     the path of the file linked to, ?""? if the path is not a symbolic
     link.

since you are referring to a file and not a link the result is as expected "" - both on OS X and Linux.


> Also, I think the readlink.h imported to R to be the same as from the system's `readlink` command, thus mimicking the command line difference.
> 
> Am I wrong with the latter? Anyway, the behaviour is irritating, thus the request to at least mention `normalizePath` in the Rd of `Sys.readlink`.
> 
> Best,
> Sven
> 
> 
>> On 29 Feb 2016, at 11:44, Mikko Korpela <mikko.korpela at aalto.fi> wrote:
>> 
>> On 29.02.2016 10:34, Sven E. Templer wrote:
>>> Hello together,
>>> 
>>> the function `Sys.readlink` uses the system's readlink command to resolve symlink paths. On OSX/BSD the command has a different meaning than on Linux [1].
>>> 
>>> There exists the tool 'realpath', which seems suitable for the task, at least applied at the command line level [2]. It is used in `normalizePath`.
>>> 
>>> I suggest (at least the latter) to
>>> * use realpath instead readlink within Sys.readlink (do_readlink -> do_normalizepath)
>>> * link to `normalizePath` in the Rd document, eventually mentioning the difference
>>> 
>>> Many thanks,
>>> Sven
>>> 
>>> [1] see
>>> https://www.freebsd.org/cgi/man.cgi?query=readlink
>>> vs
>>> http://linux.die.net/man/1/readlink
>>> 
>>> [2]
>>> https://www.freebsd.org/cgi/man.cgi?query=realpath
>>> http://linux.die.net/man/1/realpath
>> 
>> What do you mean by "different meaning"? How are the command line tools
>> [1] relevant when R is using the C function 'readlink'?
>> 
>> http://pubs.opengroup.org/onlinepubs/9699919799/functions/readlink.html
>> https://www.freebsd.org/cgi/man.cgi?query=readlink&sektion=2
>> http://man7.org/linux/man-pages/man2/readlink.2.html
>> 
>> -- 
>> Mikko Korpela
>> Aalto University School of Science
>> Department of Computer Science
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
> 



[Rd] Sys.readlink (on BSD vs Linux)
Simon Urbanek