bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: move-if-change and parallel make


From: Ralf Wildenhues
Subject: Re: move-if-change and parallel make
Date: Sun, 23 Jan 2011 09:39:59 +0100
User-agent: Mutt/1.5.20 (2010-08-04)

Hi Paul,

thanks for the review.

* Paul Eggert wrote on Sat, Jan 22, 2011 at 09:07:08PM CET:
> On 01/22/2011 08:03 AM, Ralf Wildenhues wrote:
> 
> > -if test -r "$2" && cmp -s -- "$1" "$2"; then
> > +if test -r "$2" && $cmpprog -- "$1" "$2" >/dev/null; then
> >    rm -f -- "$1"
> >  else
> > -  mv -f -- "$1" "$2"
> > +  if mv -f -- "$1" "$2"; then :; else
> > +    # Ignore failure due to a concurrent move-if-change.
> > +    $cmpprog "$1" "$2" >/dev/null 2>&1 && rm -f -- "$1"
> 
> The two cmpprog invocations should be identical, but they're
> not.  Only one has "--", and only one redirects stderr.

Yeah, I did the latter to compensate for the lack of the former,
but I guess you're right that it's better to be symmetric.

> The 1st cmppprog invocation is protected by a test -r,
> but the second one is not.  That doesn't sound right either.
> Either both should be protected, or neither.  For what
> it's worth, install-sh doesn't have the test -r.

But install-sh is different in that it is not typically used
when the first file is about to vanish.

Updated patch below.  Question remains whether the whole patch
is overkill or not?

Thanks,
Ralf

    move-if-change: cope with concurrent mv of identical file.
    
    * build-aux/move-if-change (CMPPROG): Accept environment
    variable as an override for `cmp'.
    (usage): Document CMPPROG.
    Adjust comparison to drop stdout.  Cope with failure of mv if
    the target file exists and is identical to the source, for
    parallel builds.
    Report from H.J. Lu against binutils in PR binutils/12283.

index a891ca5..71af5f7 100755
--- a/build-aux/move-if-change
+++ b/build-aux/move-if-change
@@ -2,7 +2,7 @@
 # Like mv $1 $2, but if the files are the same, just delete $1.
 # Status is zero if successful, nonzero otherwise.
 
-VERSION='2007-09-28 23:10'; # UTC
+VERSION='2011-01-23 08:40'; # UTC
 # The definition above must lie within the first 8 lines in order
 # for the Emacs time-stamp write hook (at end) to update it.
 # If you change this file with Emacs, please let the write hook
@@ -32,6 +32,8 @@ If SOURCE is different than DEST, then move it to DEST; else 
remove SOURCE.
   --help     display this help and exit
   --version  output version information and exit
 
+The variable CMPPROG can be used to specify an alternative to \`cmp'.
+
 Report bugs to <address@hidden>."
 
 version=`expr "$VERSION" : '\([^ ]*\)'`
@@ -41,6 +43,7 @@ License GPLv3+: GNU GPL version 3 or later 
<http://gnu.org/licenses/gpl.html>
 This is free software: you are free to change and redistribute it.
 There is NO WARRANTY, to the extent permitted by law."
 
+cmpprog=${CMPPROG-cmp}
 
 for arg
 do
@@ -60,12 +63,15 @@ do
   esac
 done
 
-test $# = 2 || { echo "$0: $usage" >&2; exit 1; }
+test $# -eq 2 || { echo "$0: $usage" >&2; exit 1; }
 
-if test -r "$2" && cmp -s -- "$1" "$2"; then
+if test -r "$2" && $cmpprog -- "$1" "$2" >/dev/null; then
   rm -f -- "$1"
 else
-  mv -f -- "$1" "$2"
+  if mv -f -- "$1" "$2"; then :; else
+    # Ignore failure due to a concurrent move-if-change.
+    test -r "$2" && $cmpprog -- "$1" "$2" >/dev/null && rm -f -- "$1"
+  fi
 fi
 
 ## Local Variables:



reply via email to

[Prev in Thread] Current Thread [Next in Thread]