diff mbox

[contrib] download_prerequisites: check for existing symlinks before making new ones

Message ID CAMfHzOvts48NXX+05ty43NioyiXkd_fbAjg9UTkEhq0=Du-TLA@mail.gmail.com
State New
Headers show

Commit Message

Eric Gallager July 21, 2016, 7:39 p.m. UTC
On 7/21/16, Jeff Law <law@redhat.com> wrote:
> On 07/14/2016 01:57 PM, Eric Gallager wrote:
>
>>
>> So apparently the "-f" flag properly overwrites symlinks that point to
>> regular files, but I also did this in my gcc builddir:
>>
>> $ mkdir isl-0.1.2.3
>> $ ln -s isl-0.1.2.3 isl-s
>> $ ln -sfv isl isl-s
>> isl-s/isl -> isl
>> $ ln -sfFv isl isl-s
>> isl-s/isl -> isl
>> $ ls -l isl-s
>> lrwxr-xr-x  1 root  wheel  11 Jul 14 07:03 isl-s -> isl-0.1.2.3
>> $ unlink isl-s
>> $ ln -sfFv isl isl-s
>> isl-s -> isl
>> $ ls -l isl-s
>> lrwxr-xr-x  1 root  wheel  3 Jul 14 15:51 isl-s -> isl
>>
>> ...it just doesn't overwrite symlinks that point to a directory.
> Joys :(
>
> AFAIK unlink may not necessarily be available on the various host
> systems GCC supports (solaris, aix, hpux, etc etc).
>
> So rather than relying on ln to remove the link, why don't we just
> explicitly remove it with rm -f?
>
> Jeff
>

Sure, rm -f works, too; I just went with "unlink" in my patch because
it more clearly expresses programmer intent. But I guess portability
is more important. Updated patch attached, although someone else would
have to commit it, as I don't have commit access.

Eric
contrib/download_prerequisites | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Jeff Law Aug. 3, 2016, 4:12 p.m. UTC | #1
On 07/21/2016 01:39 PM, Eric Gallager wrote:
> On 7/21/16, Jeff Law <law@redhat.com> wrote:
>> On 07/14/2016 01:57 PM, Eric Gallager wrote:
>>
>>>
>>> So apparently the "-f" flag properly overwrites symlinks that point to
>>> regular files, but I also did this in my gcc builddir:
>>>
>>> $ mkdir isl-0.1.2.3
>>> $ ln -s isl-0.1.2.3 isl-s
>>> $ ln -sfv isl isl-s
>>> isl-s/isl -> isl
>>> $ ln -sfFv isl isl-s
>>> isl-s/isl -> isl
>>> $ ls -l isl-s
>>> lrwxr-xr-x  1 root  wheel  11 Jul 14 07:03 isl-s -> isl-0.1.2.3
>>> $ unlink isl-s
>>> $ ln -sfFv isl isl-s
>>> isl-s -> isl
>>> $ ls -l isl-s
>>> lrwxr-xr-x  1 root  wheel  3 Jul 14 15:51 isl-s -> isl
>>>
>>> ...it just doesn't overwrite symlinks that point to a directory.
>> Joys :(
>>
>> AFAIK unlink may not necessarily be available on the various host
>> systems GCC supports (solaris, aix, hpux, etc etc).
>>
>> So rather than relying on ln to remove the link, why don't we just
>> explicitly remove it with rm -f?
>>
>> Jeff
>>
>
> Sure, rm -f works, too; I just went with "unlink" in my patch because
> it more clearly expresses programmer intent. But I guess portability
> is more important. Updated patch attached, although someone else would
> have to commit it, as I don't have commit access.
Thanks for your patience.  I've installed your patch.

Jeff
diff mbox

Patch

diff --git a/contrib/download_prerequisites b/contrib/download_prerequisites
index 917ee23..2c963f2 100755
--- a/contrib/download_prerequisites
+++ b/contrib/download_prerequisites
@@ -36,14 +36,17 @@  MPC=mpc-1.0.3
 
 wget ftp://gcc.gnu.org/pub/gcc/infrastructure/$MPFR.tar.bz2 || exit 1
 tar xjf $MPFR.tar.bz2 || exit 1
+if test -L mpfr; then rm -f mpfr; fi
 ln -sf $MPFR mpfr || exit 1
 
 wget ftp://gcc.gnu.org/pub/gcc/infrastructure/$GMP.tar.bz2 || exit 1
 tar xjf $GMP.tar.bz2  || exit 1
+if test -L gmp; then rm -f gmp; fi
 ln -sf $GMP gmp || exit 1
 
 wget ftp://gcc.gnu.org/pub/gcc/infrastructure/$MPC.tar.gz || exit 1
 tar xzf $MPC.tar.gz || exit 1
+if test -L mpc; then rm -f mpc; fi
 ln -sf $MPC mpc || exit 1
 
 # Necessary to build GCC with the Graphite loop optimizations.
@@ -52,5 +55,6 @@  if [ "$GRAPHITE_LOOP_OPT" = "yes" ] ; then
 
   wget ftp://gcc.gnu.org/pub/gcc/infrastructure/$ISL.tar.bz2 || exit 1
   tar xjf $ISL.tar.bz2  || exit 1
+  if test -L isl; then rm -f isl; fi
   ln -sf $ISL isl || exit 1
 fi