brp-mangle-shebangs: speed up finding of "text executables" (scripts)

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
This commit is contained in:
Denys Vlasenko 2019-11-21 15:48:07 +01:00 committed by Igor Gnatenko
parent 6335a7ff4a
commit 63d7e4dc11
No known key found for this signature in database
GPG Key ID: 695714BD1BBC5F4C
1 changed files with 12 additions and 3 deletions

View File

@ -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
}