FS#30239 - [aif] AIF incorrectly handles TARGET_PACKAGES_EXCLUDE

Attached to Project: Release Engineering
Opened by Steven Noonan (neunon) - Monday, 11 June 2012, 00:28 GMT
Last edited by Gerardo Exequiel Pozzi (djgera) - Monday, 26 November 2012, 04:54 GMT
Task Type Bug Report
Category AIF
Status Closed
Assigned To Dieter Plaetinck (Dieter_be)
Architecture All
Severity High
Priority Normal
Reported Version testbuild (specify!)
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

For example, let's say we have an AIF configuration resulting in these variables:

ALL_PACKAGES="pkg pkg-xyz xyz-pkg pkgxyz xyzpkg"
TARGET_PACKAGES_EXCLUDE="pkg"

The substitution at line 29 of core/libs/lib-software.sh looks like this in the current git tree:

if [ -n "$var_TARGET_PACKAGES_EXCLUDE" ]
then
for excl in $var_TARGET_PACKAGES_EXCLUDE
do
ALL_PACKAGES=${ALL_PACKAGES//$excl/}
done
fi

This will incorrectly result in ALL_PACKAGES="-xyz xyz- xyz xyz". The problem is that it doesn't correctly find package name boundaries (which are effectively whitespace or newlines). This is pretty easily reproducible in a bash prompt:

$ ALL_PACKAGES="pkg pkg-xyz xyz-pkg pkgxyz xyzpkg"
$ echo $ALL_PACKAGES
pkg pkg-xyz xyz-pkg pkgxyz xyzpkg
$ ALL_PACKAGES=${ALL_PACKAGES//pkg/}
$ echo $ALL_PACKAGES
-xyz xyz- xyz xyz


I replaced the substitution with this, which worked correctly:

        if [ -n "$var_TARGET_PACKAGES_EXCLUDE" ]
        then
                for excl in $var_TARGET_PACKAGES_EXCLUDE
                do
                        ALL_PACKAGES=$(echo "$ALL_PACKAGES" | awk 'BEGIN { RS="[ \t\n]+" } !/^'"$excl"'$/ { print $1 }')
                done
        fi

Here's a test case demonstrating the difference:

$ ALL_PACKAGES="pkg pkg-xyz xyz-pkg pkgxyz xyzpkg"
$ echo $ALL_PACKAGES
pkg pkg-xyz xyz-pkg pkgxyz xyzpkg
$ excl=pkg; ALL_PACKAGES=$(echo "$ALL_PACKAGES" | awk 'BEGIN { RS="[ \t\n]+" } !/^'"$excl"'$/ { print $1 }')
$ echo $ALL_PACKAGES
pkg-xyz xyz-pkg pkgxyz xyzpkg
$

The disadvantage is that this feels a bit heavy-handed and complicated. I'm just not sure how to elegantly solve the issue using bash constructs.
This task depends upon

Closed by  Gerardo Exequiel Pozzi (djgera)
Monday, 26 November 2012, 04:54 GMT
Reason for closing:  Deferred
Comment by Dave Reisner (falconindy) - Monday, 11 June 2012, 00:32 GMT
Set subtraction is a lot more readable when done via grep. All the data here should be kept in arrays, anyways. assuming that....

mapfile -t install_pkgs < <(printf %s\\n "${all_packages[@]}" | grep -xvFf <(printf %s\\n "${exclude_packages[@]}"))

Loading...