Subject: Re: bug#29266: gzip-1.8.41 test results: help-version and hard links

From: Bruno Haible <[email-masked]>
Date: Thu, 16 Nov 2017 11:37:31 +0100

Paul Eggert wrote:
> > +  ln -f "$file" "$file~" 2>/dev/null || cp -f "$file" "$file~" || {
> 
> This will be problematic if the destination already exists, as the 
> resulting permissions etc. may not be what the user intend. How about if 
> we fall back on "mv -f" instead? Although this has the disadvantage of 
> having a small window where "$file" does not exist, I think that's 
> preferable to the disadvantage of using "cp".

How about

  ln -f "$file" "$file~" 2>/dev/null || { rm -f "$file~" && cp "$file" "$file~"; } || {

then? It fixes the problem "if the destination already exists", and does
NOT leave a window where "$file" does not exist.

Bruno