Skip to content

Commit a472f99

Browse files
authored
init_buildsystem: Fix excluding /dev, /sys, etc. from preinstallimages (#1108)
- dev/* was unintentionally glob-expanded to dev/pts, use an array to avoid this - Use bsdtar and GNU tar specific ways to anchor the patterns so that /sys/* is excluded but e.g. /usr/include/sys/cdefs.h is not
1 parent f471975 commit a472f99

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

init_buildsystem

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,20 +285,21 @@ preinstall_image() {
285285
echo "unpacking preinstall image${2:+ $2}"
286286
preinstall_setup
287287

288-
TAR_EXCLUDES="--exclude .build --exclude .init_b_cache"
288+
TAR_EXCLUDES=(.build .init_b_cache)
289289

290290
if [ -f "/run/.containerenv" ]; then
291291
# we're running in a podman container and we probably don't have sufficient capabilities to create special files
292-
TAR_EXCLUDES="$TAR_EXCLUDES --exclude dev/* --exclude proc/* --exclude run/* --exclude sys/*"
292+
TAR_EXCLUDES+=("dev/*" "proc/*" "run/*" "sys/*")
293293
fi
294294

295295
if test -x /usr/bin/bsdtar ; then
296-
TAR="/usr/bin/bsdtar $TAR_EXCLUDES -P --chroot --numeric-owner -x"
296+
# Undocumented bsdtar feature: ^ at the beginning anchors
297+
TAR=(/usr/bin/bsdtar "${TAR_EXCLUDES[@]/#/"--exclude=^"}" -P --chroot --numeric-owner -x)
297298
else
298299
unsafe_preinstall_check
299-
TAR="tar $TAR_EXCLUDES -x"
300+
TAR=(tar --anchored "${TAR_EXCLUDES[@]/#/"--exclude="}" -x)
300301
fi
301-
if ! $TAR -f "$BUILD_INIT_CACHE/rpms/$1" ; then
302+
if ! "${TAR[@]}" -f "$BUILD_INIT_CACHE/rpms/$1" ; then
302303
echo "ERROR: unpack failed."
303304
if test "x$(od -t x4 -A n -N 4 "$BUILD_INIT_CACHE/rpms/$1")" = "x fd2fb528" ; then
304305
echo "ERROR: This is a .zst compressed preinstallimage and $TAR failed to unpack."

0 commit comments

Comments
 (0)