libmakepkg: strip - parallelize stripping of files
Perform file stripping in parallel where possible. Hardlinks remain processed one at a time due to reproducibility issues. Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
parent
dbde37aafb
commit
02b35b9155
2 changed files with 24 additions and 3 deletions
|
@ -190,9 +190,27 @@ tidy_strip() {
|
||||||
mkdir -p "$dbgdir" "$dbgsrc"
|
mkdir -p "$dbgdir" "$dbgsrc"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
while IFS= read -rd '' binary ; do
|
_parallel_stripper() {
|
||||||
process_file_stripping "$binary"
|
# Inherit traps in subshell to perform cleanup after an interrupt
|
||||||
done < <(find . -type f -perm -u+w -links 1 -print0 2>/dev/null)
|
set -E
|
||||||
|
(
|
||||||
|
local jobs binary
|
||||||
|
|
||||||
|
while IFS= read -rd '' binary ; do
|
||||||
|
# Be sure to keep the number of concurrently running processes less
|
||||||
|
# than limit value to prevent an accidental fork bomb.
|
||||||
|
jobs=($(jobs -p))
|
||||||
|
(( ${#jobs[@]} >= $NPROC )) && wait -n "${jobs[@]}"
|
||||||
|
|
||||||
|
process_file_stripping "$binary" &
|
||||||
|
done < <(find . -type f -perm -u+w -links 1 -print0 2>/dev/null)
|
||||||
|
|
||||||
|
# Wait for all jobs to complete
|
||||||
|
wait
|
||||||
|
)
|
||||||
|
set +E
|
||||||
|
}
|
||||||
|
_parallel_stripper
|
||||||
|
|
||||||
# hardlinks only need processed once, but need additional links in debug packages
|
# hardlinks only need processed once, but need additional links in debug packages
|
||||||
declare -A hardlinks
|
declare -A hardlinks
|
||||||
|
|
|
@ -106,6 +106,9 @@ trap_exit() {
|
||||||
fi
|
fi
|
||||||
[[ -n $srclinks ]] && rm -rf "$srclinks"
|
[[ -n $srclinks ]] && rm -rf "$srclinks"
|
||||||
|
|
||||||
|
# Kill all child processes so that they are not left orphaned upon exit.
|
||||||
|
[[ -n "$(jobs -p)" ]] && kill "$(jobs -p)" 2>/dev/null
|
||||||
|
|
||||||
# unset the trap for this signal, and then call the default handler
|
# unset the trap for this signal, and then call the default handler
|
||||||
trap -- "$signal"
|
trap -- "$signal"
|
||||||
kill "-$signal" "$$"
|
kill "-$signal" "$$"
|
||||||
|
|
Loading…
Add table
Reference in a new issue