Here's a little patch does a couple of things for the check-files script:
authorArchie Cobbs <archie@dellroad.org>
Fri, 26 Apr 2013 09:28:03 +0000 (12:28 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Fri, 7 Jun 2013 09:26:00 +0000 (12:26 +0300)
- Eliminates the use of one of the two temporary files
- Ensures the other temporary file gets cleaned up in all termination
  scenarios
- Performs the difference check more efficiently

Signed-off-by: Panu Matilainen <pmatilai@redhat.com>
(cherry picked from commit d7b393a512cd46ef2d6889574af3060a267fed40)

scripts/check-files

index cbdf740..ec4cf5c 100755 (executable)
@@ -6,24 +6,27 @@
 #
 # filon@pld.org.pl
 
-RPM_BUILD_ROOT=$1
+# Get build root
+RPM_BUILD_ROOT="${1}"
 
-if [ ! -d "$RPM_BUILD_ROOT" ] ; then
+# Handle the case where ${RPM_BUILD_ROOT} is undefined, not a directory, etc.
+if [ ! -d "${RPM_BUILD_ROOT}" ] ; then
        cat > /dev/null
+       if [ -e "${RPM_BUILD_ROOT}" ] ; then
+               echo "Error: \`${RPM_BUILD_ROOT}' is not a directory" 1>&2
+       fi
        exit 1
 fi
 
-[ "$TMPDIR" ] || TMPDIR=/tmp
-FILES_DISK=`mktemp $TMPDIR/rpmXXXXXX`
-FILES_RPM=`mktemp $TMPDIR/rpmXXXXXX`
+# Create temporary file listing files in the manifest
+[ -n "$TMPDIR" ] || TMPDIR="/tmp"
+FILES_DISK=`mktemp "${TMPDIR}/rpmXXXXXX"`
 
-find "$RPM_BUILD_ROOT" -type f -o -type l | LC_ALL=C sort > $FILES_DISK
-LC_ALL=C sort > $FILES_RPM
+# Ensure temporary file is cleaned up when we exit
+trap "rm -f \"${FILES_DISK}\"" 0 2 3 5 10 13 15
 
-diff -d "$FILES_DISK" "$FILES_RPM" | grep "^< " | cut -c3- | 
-while read f; do
-       echo $f | sed -e "s#^$RPM_BUILD_ROOT#   #g"
-done
+# Find non-directory files in the build root and compare to the manifest.
+# TODO: regex chars in last sed(1) expression should be escaped
+find "${RPM_BUILD_ROOT}" -type f -o -type l | LC_ALL=C sort > "${FILES_DISK}"
+LC_ALL=C sort | diff -d "${FILES_DISK}" - | sed -n 's|^< '"${RPM_BUILD_ROOT}"'\(.*\)$|   \1|gp'
 
-rm -f $FILES_DISK
-rm -f $FILES_RPM