[PATCH 02/20] scripts/make-erofs.sh: Do not read one byte at a time

Demi Marie Obenour
2025-09-04T23:47:50Z

POSIX requires that the shell read builtin not consume any bytes beyond
the end-of-line character. For non-seekable files like pipes, this
requirement can only be met by reading one byte at a time, which is very
slow. Avoid this by reading the entire input into a temporary file and
having sh read from the temporary file. Since regular files are
seekable, sh can read many bytes and then seek back to the correct file
position.

Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com>
---
scripts/make-erofs.sh | 2 ++
1 file changed, 2 insertions(+)

diff --git a/scripts/make-erofs.sh b/scripts/make-erofs.sh
index 88e3885e578a6fd85a61c6f2993a9addb7f44c37..3f211d848b938405510d0dbf6b11cf5512c9ef5d 100755
--- a/scripts/make-erofs.sh
+++ b/scripts/make-erofs.sh
@@ -20,6 +20,8 @@ if [ -z "${img-}" ]; then
fi

superroot="$(mktemp -d -- "$img.tmp.XXXXXXXXXX")"
+cat > "$superroot/input_files"
+exec < "$superroot/input_files"
trap 'chmod -R +w -- "$root" && rm -rf -- "$superroot"' EXIT
# $superroot has 0700 permissions, so create a subdirectory
# with correct (0755) permissions and do all work there.

--
2.51.0