readahead-fedora (2:1.5.6-4) more_efficient_build-lists.patch

Summary

 scripts/readahead.cron |   66 ++++++++++++++++++++++++++++++++++---------------
 1 file changed, 47 insertions(+), 19 deletions(-)

    
download this patch

Patch contents

Index: readahead/scripts/readahead.cron
===================================================================
--- readahead.orig/scripts/readahead.cron
+++ readahead/scripts/readahead.cron
@@ -3,6 +3,7 @@
 #
 # Generates sorted readahead files
 #
+# Copyright (C) 2009, 2011 by Raphael Geissert
 # Copyright (C) 2007  Red Hat, Inc.
 # Karel Zak <kzak@redhat.com>
 #
@@ -27,21 +28,27 @@ if [ -f /run/readahead ]; then
     fi
 fi
 
-for LTYPE in $TYPES; do
-	if [ -s "$READAHEAD_BASE/custom.$LTYPE" ]; then
-		FLS="$READAHEAD_BASE/custom.$LTYPE"
-	else
-		FLS=$(ls $READAHEAD_BASE/*.$LTYPE 2>/dev/null )
-	fi
-	
-	if [ -n "$FLS" ]; then
-		$READAHEAD_CMD --sort --output=$READAHEAD_BASE/$LTYPE.sorted $FLS >/dev/null 2>&1
+get_lists() {
+    local type="$1" allow_null="${2:-true}"
+
+    if [ -s "$READAHEAD_BASE/custom.$type" ]; then
+	echo "$READAHEAD_BASE/custom.$type"
+    else
+	local f found=false
+	for f in "$(ls $READAHEAD_BASE/*.$type 2>/dev/null)"; do
+	    if [ -f "$f" ]; then
+		echo "$f"
+		found=true
+	    fi
+	done
+	if ! $found && $allow_null; then
+	    # otherwise readahead(8) would abort
+	    echo /dev/null
 	fi
-done
+    fi
+}
 
 if $MERGE_LISTS; then
-    tmpf="$(mktemp)"
-
     extra_opts=--sort
 
     major=$(stat -c '%D' . | cut -b1)
@@ -52,14 +59,35 @@ if $MERGE_LISTS; then
 	fi
     fi
 
-    for LTYPE in $TYPES; do
-	f="$READAHEAD_BASE/$LTYPE.sorted"
-	[ -f "$f" ] || continue
-	cut -d\  -f2- "$f" >> "$tmpf"
+    lists=
+    for type in $TYPES; do
+	typel="$(get_lists $type false)"
+
+	# We don't want lists=" /etc/..." because of the -n test below
+	# We need lists='' instead of lists='  ' when no list is found
+	if [ -n "$lists" ]; then
+	    lists="$typel"
+	else
+	    lists="$lists $typel"
+	fi
     done
-    if [ -s "$tmpf" ]; then
-	$READAHEAD_CMD $extra_opts --output="$READAHEAD_BASE/early.sorted" "$tmpf" >/dev/null 2>&1
+
+    if [ -n "$lists" ]; then
+	$READAHEAD_CMD $extra_opts --output="$READAHEAD_BASE/early.sorted" $lists >/dev/null 2>&1
+	# only write to later.sorted if needed
+	if [ ! -f "$READAHEAD_BASE/later.sorted" ] || [ -s "$READAHEAD_BASE/later.sorted" ]; then
+	    : > "$READAHEAD_BASE/later.sorted"
+	fi
+    else
+	: > "$READAHEAD_BASE/early.sorted"
 	: > "$READAHEAD_BASE/later.sorted"
     fi
-    rm -f "$tmpf"
+else
+    for LTYPE in $TYPES; do
+	FLS="$(get_lists $LTYPE)"
+
+	if [ -n "$FLS" ]; then
+	    $READAHEAD_CMD --sort --output=$READAHEAD_BASE/$LTYPE.sorted $FLS >/dev/null 2>&1
+	fi
+    done
 fi