Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
Date: Sat, 9 Jul 2005 12:34:18 -0400
From: Christopher Faylor <cgf-no-personal-reply-please@cygwin.com>
To: cygwin@cygwin.com
Subject: Re: Unwanted .exe appended to symlinks
Message-ID: <20050709163418.GB11356@trixie.casa.cgf.cx>
Reply-To: cygwin@cygwin.com
References: <1120880636.6400.7.camel@localhost.localdomain> <42CF4C9D.8000708@byu.net> <20050709050214.GA10083@trixie.casa.cgf.cx> <42CFBE28.3060808@byu.net> <20050709163242.GA11356@trixie.casa.cgf.cx>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20050709163242.GA11356@trixie.casa.cgf.cx>
User-Agent: Mutt/1.5.8i

On Sat, Jul 09, 2005 at 12:32:43PM -0400, Christopher Faylor wrote:
>On Sat, Jul 09, 2005 at 06:08:08AM -0600, Eric Blake wrote:
>>-----BEGIN PGP SIGNED MESSAGE-----
>>Hash: SHA1
>>
>>According to Christopher Faylor on 7/8/2005 11:02 PM:
>>> I don't get it.  Certainly /cygdrive/c.exe doesn't exist so why would you
>>> try to link to it?
>>
>>The algorithm I used was this:
>>
>>1 - If source exists [determined by the return value of readlink
>>("source"), although just now I realized that for symbolic links, it
>>should really be the return value of readlink (concat (dirname ("dest"),
>>"source")) since symbolic links are relative to the destination, not the pwd]
>> 2a - if source is non-symlink and exists with a trailing . [determined by
>>access ("source.")] use "source", else use "source.exe", because one of
>>those two spellings must have made test 1 succeed
>> 2b - if source is symlink and exists with a trailing .lnk [determined by
>>readlink ("source.lnk")] use "source", else use "source.exe", because one
>>of those two spellings must have made test 1 succeed
>>
>>I think the cleanup needs to be along these lines - in steps 2a and 2b, do
>>a sanity check of also checking whether "source.exe" exists.
>
>I don't know why you'd ever just assume that .exe exists.
>
>Wouldn't it be safer to just do:
>
>  struct stat st1, st2;
>
>  stat ("foo", &st1);
>
>  if (stat ("foo.exe", &st2) == 0 && st2.st_ino == st1.st_ino)
>    return "foo.exe";
>  else
>    return "foo";
>
>You could add st_dev checking, too, if you were really paranoid.

You can also replace "stat" with "lstat" as appropriate, of course.

cgf

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

