summaryrefslogtreecommitdiff
path: root/build-aux/move-if-change
diff options
context:
space:
mode:
authorRalf Wildenhues <Ralf.Wildenhues@gmx.de>2011-01-22 16:44:52 +0100
committerRalf Wildenhues <Ralf.Wildenhues@gmx.de>2011-01-28 21:09:29 +0100
commit59211b860544f8ec53420147785fa16ed298c681 (patch)
treec6d7368d95f73c4933ef853dc1309cd1e471ef57 /build-aux/move-if-change
parentd15ae07e45e02d780e6c39e1ed3ced5e188cba5f (diff)
downloadgnulib-59211b860544f8ec53420147785fa16ed298c681.tar.gz
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. Signed-off-by: Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
Diffstat (limited to 'build-aux/move-if-change')
-rwxr-xr-xbuild-aux/move-if-change16
1 files changed, 11 insertions, 5 deletions
diff --git a/build-aux/move-if-change b/build-aux/move-if-change
index a891ca51f0..e7ba25e312 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-28 20:09'; # 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,15 +32,18 @@ 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 <bug-gnulib@gnu.org>."
version=`expr "$VERSION" : '\([^ ]*\)'`
version="move-if-change (gnulib) $version
-Copyright (C) 2007 Free Software Foundation, Inc.
+Copyright (C) 2011 Free Software Foundation, Inc.
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: