aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbrp-mangle-shebangs15
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
+}