makronix-set: two processes a file instead of ten (98 s -> 31 s)
The loop over the ~12000 files of the set asked stat(1) three times, each helper twice (once to see which stat this is), plus sed and sha256sum|awk: 95 of the 97 s of 'set and repository' (userland-2026-11-17j.log). The kind of stat and sha256 is decided once, mode/type/size come from one stat call, sed runs only for a path with //. Run on the sysroot of release-2026-11-17 after the old one: list and METALOG byte-identical, 98 s -> 31 s; test-tools.sh 34 ok. NetBSD's stat -f %Lp is octal digits already: printed %04d now (the old %04o turned 755 into 1363).
This commit is contained in:
1 parent
d4020e7c5c
commit
fcee679eb5
1 file changed
+30
-35
+30
-35
@@ -58,47 +58,40 @@ fi
|
||||
tmp=$(mktemp -d "${TMPDIR:-/tmp}/makronix-set.XXXXXX")
|
||||
trap 'rm -rf "${tmp}"' EXIT
|
||||
|
||||
# Which stat(1) and which sha256 this host has, decided once: the loop below
|
||||
# runs for every file of the set (about 12000), and the helpers used to ask
|
||||
# again each time -- ten processes a file, 95 of the 97 s of the step
|
||||
# (build/logs/userland-2026-11-17j.log, "set and repository"). Now two.
|
||||
if stat -c '%04a' / > /dev/null 2>&1; then GNUSTAT=yes; else GNUSTAT=; fi
|
||||
if command -v sha256sum > /dev/null 2>&1; then HAVE_SHA256SUM=yes; else HAVE_SHA256SUM=; fi
|
||||
|
||||
sha256_file()
|
||||
{
|
||||
if command -v sha256sum >/dev/null 2>&1; then
|
||||
sha256sum "$1" | awk '{print $1}'
|
||||
if [ -n "$HAVE_SHA256SUM" ]; then
|
||||
s=$(sha256sum "$1")
|
||||
echo "${s%% *}"
|
||||
else
|
||||
cksum -a sha256 "$1" | awk '{print $NF}'
|
||||
fi
|
||||
}
|
||||
|
||||
stat_mode()
|
||||
# mode, type and size in one call: "MODE|TYPE|SIZE", the type as GNU stat
|
||||
# names it. NetBSD's %Lp is already octal digits ("755"): printed as a
|
||||
# decimal with four places it is 0755 (the old printf "%04o" made it 1363).
|
||||
stat_all()
|
||||
{
|
||||
if stat -c '%04a' "$1" >/dev/null 2>&1; then
|
||||
stat -c '%04a' "$1"
|
||||
if [ -n "$GNUSTAT" ]; then
|
||||
stat -c '%04a|%F|%s' "$1"
|
||||
else
|
||||
stat -f '%Lp' "$1" | awk '{printf "%04o", $1}'
|
||||
stat -f '%Lp|%HT|%z' "$1" | awk -F'|' '{
|
||||
t = $2
|
||||
if (t == "Directory") t = "directory"
|
||||
else if (t == "Symbolic Link") t = "symbolic link"
|
||||
else if (t == "Regular File") t = (($3 + 0) == 0) ? "regular empty file" : "regular file"
|
||||
printf "%04d|%s|%s\n", $1, t, $3 }'
|
||||
fi
|
||||
}
|
||||
|
||||
stat_size()
|
||||
{
|
||||
if stat -c '%s' "$1" >/dev/null 2>&1; then
|
||||
stat -c '%s' "$1"
|
||||
else
|
||||
stat -f '%z' "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
stat_type()
|
||||
{
|
||||
if stat -c '%F' "$1" >/dev/null 2>&1; then
|
||||
stat -c '%F' "$1"
|
||||
else
|
||||
t=$(stat -f '%HT' "$1")
|
||||
case "$t" in
|
||||
"Directory") echo "directory" ;;
|
||||
"Symbolic Link") echo "symbolic link" ;;
|
||||
"Regular File") echo "regular file" ;;
|
||||
*) echo "$t" ;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
|
||||
# Resolve set package base names to installed full package names in sysroot db.
|
||||
: > "${tmp}/seed"
|
||||
@@ -226,7 +219,7 @@ LC_ALL=C sort -u "${tmp}/pkgs" | while IFS= read -r pkg; do
|
||||
# "extra files in DESTDIR" for the directory
|
||||
# (build/logs/release-2026-11-15b-chain.log:79042)
|
||||
rel="${cwd}/${line#@pkgdir }"
|
||||
rel=$(printf '%s\n' "$rel" | sed 's#//*#/#g')
|
||||
case "$rel" in *//*) rel=$(printf '%s\n' "$rel" | sed 's#//*#/#g') ;; esac
|
||||
case "$rel" in /usr/pkg/pkgdb/*|/usr/pkg/pkgdb|/usr/pkg/share/x11-links/*|/usr/pkg/share/x11-links) ;; *)
|
||||
if [ -d "${DESTDIR}${rel}" ]; then
|
||||
printf './%s\tmakronix-sys-root\n' "${rel#/}" >> "${tmp}/list"
|
||||
@@ -242,7 +235,7 @@ LC_ALL=C sort -u "${tmp}/pkgs" | while IFS= read -r pkg; do
|
||||
if [ -n "$prev" ]; then
|
||||
target=${line#@comment Symlink:}
|
||||
rel="${cwd}/${prev}"
|
||||
rel=$(printf '%s\n' "$rel" | sed 's#//*#/#g')
|
||||
case "$rel" in *//*) rel=$(printf '%s\n' "$rel" | sed 's#//*#/#g') ;; esac
|
||||
case "$rel" in /usr/pkg/pkgdb/*|/usr/pkg/pkgdb|/usr/pkg/share/x11-links/*|/usr/pkg/share/x11-links) ;; *)
|
||||
entry=".${rel}"
|
||||
sp=makronix-util-data
|
||||
@@ -267,7 +260,7 @@ LC_ALL=C sort -u "${tmp}/pkgs" | while IFS= read -r pkg; do
|
||||
|
||||
# path entry
|
||||
rel="${cwd}/${line}"
|
||||
rel=$(printf '%s\n' "$rel" | sed 's#//*#/#g')
|
||||
case "$rel" in *//*) rel=$(printf '%s\n' "$rel" | sed 's#//*#/#g') ;; esac
|
||||
full="${DESTDIR}${rel}"
|
||||
# a name with a space fits neither a set list nor METALOG (nbmtree: unknown
|
||||
# keyword `ipsum.txt', build/logs/checkflist 2026-11-14); three templates of
|
||||
@@ -278,8 +271,11 @@ LC_ALL=C sort -u "${tmp}/pkgs" | while IFS= read -r pkg; do
|
||||
sp=makronix-util-data
|
||||
case "$rel" in /usr/pkg/lib/*) sp=makronix-lib-shlib ;; /usr/pkg/include/*) sp=makronix-util-include ;; /usr/pkg/share/man/*) sp=makronix-util-man ;; /usr/pkg/*bin/*) sp=makronix-util-bin ;; esac
|
||||
entry=".${rel}"
|
||||
mode=$(stat_mode "$full")
|
||||
tt=$(stat_type "$full")
|
||||
st=$(stat_all "$full")
|
||||
mode=${st%%|*}
|
||||
st=${st#*|}
|
||||
tt=${st%%|*}
|
||||
size=${st#*|}
|
||||
case "$tt" in
|
||||
directory)
|
||||
printf './%s\t%s\n' "${rel#/}" "makronix-sys-root" >> "${tmp}/list"
|
||||
@@ -290,7 +286,6 @@ LC_ALL=C sort -u "${tmp}/pkgs" | while IFS= read -r pkg; do
|
||||
printf '%s type=link uname=root gname=wheel mode=0777 link=%s\n' "$entry" "$(readlink "$full")" >> "${tmp}/metalog"
|
||||
;;
|
||||
"regular file"|"regular empty file")
|
||||
size=$(stat_size "$full")
|
||||
sum=$(sha256_file "$full")
|
||||
printf './%s\t%s\n' "${rel#/}" "$sp" >> "${tmp}/list"
|
||||
printf '%s type=file uname=root gname=wheel mode=%s size=%s sha256=%s\n' "$entry" "$mode" "$size" "$sum" >> "${tmp}/metalog"
|
||||
|
||||
Reference in new issue
Block a user