build: ipkg-remove: fix source name / package confusion, optimize
authorFelix Fietkau <[email protected]>
Tue, 15 Jul 2025 13:26:16 +0000 (15:26 +0200)
committerFelix Fietkau <[email protected]>
Thu, 17 Jul 2025 08:46:39 +0000 (10:46 +0200)
The script always gets passed the package name, not the source name.
Optimize for the default case where the package name matches the
filename prefix.

Signed-off-by: Felix Fietkau <[email protected]>
(cherry picked from commit 471fd0a50281ce2a37fece402c4c5bd609b6d580)

scripts/ipkg-remove

index f4957004c0ebcabba2b8d301c2888e555929f38b..19d7148e83c5a4c3d44760fe73dc1120b55ce3b7 100755 (executable)
@@ -3,17 +3,24 @@
 sourcename="$1"; shift
 
 for pkg in "$@"; do
-       tar -Ozxf "$pkg" ./control.tar.gz 2>/dev/null | tar -Ozxf - ./control 2>/dev/null | \
-       while read field value; do
-               if [ "$field" = "SourceName:" ] && [ "$value" = "$sourcename" ]; then
-                       rm -vf "$pkg"
-                       break
-               fi
-       done
        case "$pkg" in
                */"${sourcename}_"*.ipk)
                        rm -vf "$pkg"
                ;;
+               *)
+                       tar -Ozxf "$pkg" ./control.tar.gz 2>/dev/null | tar -Ozxf - ./control 2>/dev/null | {
+                               packagename=
+                               abiversion=
+                               while read field value; do
+                                       case "$field" in
+                                               Package:) packagename="$value";;
+                                               ABIVersion:) abiversion="$value";;
+                                       esac
+                               done
+                               [ -n "$abiversion" ] && packagename="${packagename%%$abiversion}"
+                               [ "$packagename" = "$sourcename" ] && rm -vf "$pkg"
+                       }
+               ;;
        esac
 done