From 63d7e4dc112b2b4544813059f9be057f488a2ffd Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 21 Nov 2019 15:48:07 +0100 Subject: [PATCH] brp-mangle-shebangs: speed up finding of "text executables" (scripts) Signed-off-by: Denys Vlasenko --- brp-mangle-shebangs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/brp-mangle-shebangs b/brp-mangle-shebangs index 67a1a7d..d79af5a 100755 --- a/brp-mangle-shebangs +++ b/brp-mangle-shebangs @@ -74,9 +74,17 @@ trim() { printf '%s' "$*" } +# Large packages such as kernel can have thousands of executable files. +# We take care to not fork/exec thousands of "file"s and "grep"s, +# but run just two of them. +# (Take care to exclude filenames which would mangle "file" output). +find -executable -type f ! -path '*:*' ! -path $'*\n*' \ +| file -N --mime-type -f - \ +| grep -P ".+(?=: text/)" \ +| { fail=0 -while IFS= read -r -d $'\0' f; do - file -N --mime-type "$f" | grep -q -P ".+(?=: text/)" || continue +while IFS= read -r line; do + f=${line%%:*} # Remove the dot path="${f#.}" @@ -137,6 +145,7 @@ while IFS= read -r -d $'\0' f; do fi touch -d "$ts" "$f" -done < <(find -executable -type f -print0) +done exit $fail +}