Check for sort errors
authorSteve McIntyre <steve@einval.com>
Mon, 6 Jun 2011 12:59:16 +0000 (13:59 +0100)
committerSteve McIntyre <steve@einval.com>
Mon, 6 Jun 2011 12:59:16 +0000 (13:59 +0100)
mkjigsnap

index f9d0a32..507697c 100755 (executable)
--- a/mkjigsnap
+++ b/mkjigsnap
@@ -440,12 +440,20 @@ for KEYWORD in $KEYWORDS; do
     TOTAL_FILES=`wc -l < $TMPFILE`
     echo "  $LISTDONEDATE: Total references for \"$KEYWORD\": $TOTAL_FILES"
 
-    cat $TMPFILE | sort -u $SORT_TMPDIR > $TMPFILE1
+    # sort is prone to running out of space, so bail if it fails. We
+    # don't want to destroy an existing snapshot if we end up with an
+    # empty list of files!
+    sort -u $SORT_TMPDIR $TMPFILE > $TMPFILE1
     SORTDONEDATE=`date -u`
     mv -f $TMPFILE1 $TMPFILE
     NUM_FILES=`wc -l < $TMPFILE`
     echo "  $SORTDONEDATE: Unique references for \"$KEYWORD\": $NUM_FILES"
 
+    if [ $NUM_FILES -lt 5 ] ; then
+        echo "    Only $NUM_FILES for the snapshot? Something is wrong; abort!"
+        exit 1
+    fi
+
     echo "Creating snapshot tree in $DIRNAME:"
     generate_snapshot_tree "$NUM_FILES" "$MIRROR" "$DIRNAME" "$FAILEDFILE" "$IGNOREFILE" "$TMPFILE"
     SNAPDONEDATE=`date -u`