diff options
author | Denys Vlasenko <dvlasenk@redhat.com> | 2019-11-21 15:48:07 +0100 |
---|---|---|
committer | Thierry Vignaud <thierry.vignaud@gmail.com> | 2019-12-23 16:02:47 +0100 |
commit | 7944a0608672698b96767550fa265fde01f29bf0 (patch) | |
tree | 070bb8ff229895bac4d2eb88469691fb540ef284 | |
parent | 79b7c83712f59282c61ceb33c0fedb087bc26530 (diff) | |
download | rpm-setup-7944a0608672698b96767550fa265fde01f29bf0.tar rpm-setup-7944a0608672698b96767550fa265fde01f29bf0.tar.gz rpm-setup-7944a0608672698b96767550fa265fde01f29bf0.tar.bz2 rpm-setup-7944a0608672698b96767550fa265fde01f29bf0.tar.xz rpm-setup-7944a0608672698b96767550fa265fde01f29bf0.zip |
brp-mangle-shebangs: speed up finding of "text executables" (scripts)
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
-rwxr-xr-x | brp-mangle-shebangs | 15 |
1 files 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 +} |