On 29 nov. 2010, at 16:59, David M. Lloyd wrote:
On 11/29/2010 08:04 AM, Emmanuel Bernard wrote:
>
> On 28 nov. 2010, at 23:03, David M. Lloyd wrote:
>
>> On 11/28/2010 10:18 AM, Emmanuel Bernard wrote:
>>> Hey guys,
>>> Over the week-end I've packaged JBoss AS 6 into HomeBrew (a Mac OS X
packaging system made of git and ruby).
>>> I've discovered that our scripts are not symlinks friendly and will fail
(often not finding the jars).
>>>
>>> I've fixed the issue but I wanted to get a review of my work. Let me know
if you thing there could be a problem, otherwise I'll apply them to SVN.
>>> [...]
>>> ls=`ls -ld "$PRG"`
>>> link=`expr "$ls" : '.*-> \(.*\)$'`
>>
>> This is fragile I think. It'd probably be better to use
"readlink"
>> instead, whose actual purpose is to read links.
>
> I've tried your approach but I had a couple of issues. The main one is that
readlink -f (recursive) is not standard across all platforms. The second issue I had was
that readlink sometimes return links to the script basedir, sometimes as absolute. I
imagine I could circumvent issue 2 (I've something for issue 1) but the fix will
likely end up as weak as the original proposal (that comes from mvn, tomcat and co, so I
imagine is decently battle tested).
>
> Is that worth the work?
I guess it depends on how sure you are that "ls" will always output the link
target after a "->". I guess we could always try it and see if anyone
complains.
The good news is that /man/ explicitly talk about '->' :)
If the file is a symbolic link, the pathname of the linked-to file is preceded by
``->''.