From a9b38b383473df247e2ac6b2582e83e5752fa52e Mon Sep 17 00:00:00 2001 From: gord-fig Date: Tue, 25 Sep 2001 22:21:14 +0000 Subject: [PATCH] Preserve timestamps if a patch made no changes. --- lustre/scripts/patch-if-change | 50 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100755 lustre/scripts/patch-if-change diff --git a/lustre/scripts/patch-if-change b/lustre/scripts/patch-if-change new file mode 100755 index 0000000..4dd4079 --- /dev/null +++ b/lustre/scripts/patch-if-change @@ -0,0 +1,50 @@ +#! /bin/sh +# patch-if-change - Copy FILES to the current directory, apply PATCH, +# and restore timestamps on files that weren't changed. +# Gordon Matzigkeit , 2001-09-25 + +# Usage: patch-if-change [PATCHFLAGS]... PATCH FILES... +PATCHFLAGS= +PATCH= +FILES= + +# Arguments beginning with a dash are interpreted as options for +# patch. +# The first non-option is the patch file, and the rest are files to be +# preserved. +for arg +do + case "$arg" in + -*) PATCHFLAGS="$PATCHFLAGS $arg" ;; + *) + if test -z "$PATCH"; then + PATCH="$arg" + else + FILES="$FILES $arg" + fi + ;; + esac +done + +# Make backups of all the affected files. +for file in $FILES; do + oldfile=`echo "$file" | sed -e 'sX.*/XX'` + test -f $oldfile && { cp -p $oldfile $oldfile.backup || exit $?; } + cp $file . || exit $? +done + +# Apply the patch. +patch $PATCHFLAGS < $PATCH + +# Revert the files that didn't change. +for file in $FILES; do + oldfile=`echo "$file" | sed -e 'sX.*/XX'` + test -f $oldfile.backup || continue + if cmp -s $oldfile $oldfile.backup; then + mv -f $oldfile.backup $oldfile + else + rm -f $oldfile.backup + fi +done + +exit 0 -- 1.8.3.1