Use python-rpm to uninstall packages.
authorwanchao-xu <wanchao.xu@samsung.com>
Tue, 3 Sep 2024 03:36:58 +0000 (11:36 +0800)
committerwanchao-xu <wanchao.xu@samsung.com>
Tue, 3 Sep 2024 03:36:58 +0000 (11:36 +0800)
  * python-rpm can use 'addErase' and 'run' to remove packages, but python3-rpm has a crash bug.
  * It' unnecessary chroot into image to uninstall packages by rpm command.

Change-Id: I07d1c3131e7f6300c65a77ac7e30f1ec68463764
Signed-off-by: wanchao-xu <wanchao.xu@samsung.com>
plugins/backend/zypppkgmgr.py

index bbaee014e6ade487e9fbd002cc37694aa276b29c..79beca0f43cd28a820b049144c053481eab94929 100644 (file)
@@ -1098,8 +1098,6 @@ exit 0
                 self.show_unresolved_dependencies_msg(unresolved_dependencies)
                 raise RpmError("Unresolved dependencies, transaction failed.")
 
-        # python rpm has a crash bug while use 'addErase' and 'run' to remove packages
-        """
         cb = rpmmisc.RPMInstallCallback(self.ts)
         logfile = "%s/__catched_stderr.buf" % (self.instroot)
 
@@ -1121,58 +1119,47 @@ exit 0
                 for e in errors:
                     msger.warning(e[0])
                 raise RpmError('Could not run transaction.')
-        """
-
-        self.ts.closeDB()
-        self.ts = None
 
-        # chroot into install root and remove packages with rpm cmd
-        # note: the rpm package should has been installed in install root
-        # some rpm packages only include tpk package, them should be uninstalled
+        # chroot into install root and remove preload packages
+        # note: the preload packages are installed by posttrans script of pkgmgr package
         script = """#!/bin/bash
 pkgs=$1
 if [ -n "$pkgs" ]; then
-  if [ -f /usr/bin/rpm ]; then
-    rpm -e --allmatches $pkgs
-    if [ -f /usr/bin/pkgcmd ]; then
-      for pkg in $pkgs; do
-        result=$(pkgcmd -l --global | grep -m 1 $pkg)
-        pkgid=$(echo ${result#*pkgid} | awk -F ' ' '{print $1}' | sed 's/.*\\[\\(.*\\)\\].*/\\1/')
-        if [ -n "$pkgid" ]; then
-          echo "Uninstalling preload $pkgtype package $pkgid ..."
-          pkginfo=$(pkginfo --pkg $pkgid)
-          pkgtype=$(echo "$pkginfo" | grep "Type:" | awk -F ': ' '{print $2}')
-          preload=$(echo "$pkginfo" | grep "Preload:" | awk -F ': ' '{print $2}')
-          readonly=$(echo "$pkginfo" | grep "Readonly:" | awk -F ': ' '{print $2}')
-          options=""
-          if [[ $pkgtype == 'tpk' ]]; then
-            cmd='/usr/bin/tpk-backend'
-          elif [[ $pkgtype == 'wgt' ]]; then
-            cmd='/usr/bin/wgt-backend'
-          else
-            cmd='/usr/bin/unified-backend'
-          fi
-          if [[ $preload == "1" ]]; then
-            if [[ $readonly == "1" ]]; then
-              options="--preload"
-            else
-              options="--preload-rw"
-            fi
-          fi
-          if [ -f $cmd ]; then
-            $cmd -d $pkg $options --force-remove
+  if [ -f /usr/bin/pkgcmd ]; then
+    for pkg in $pkgs; do
+      result=$(pkgcmd -l --global | grep -m 1 $pkg)
+      pkgid=$(echo ${result#*pkgid} | awk -F ' ' '{print $1}' | sed 's/.*\\[\\(.*\\)\\].*/\\1/')
+      if [ -n "$pkgid" ]; then
+        echo "Uninstalling preload $pkgtype package $pkgid ..."
+        pkginfo=$(pkginfo --pkg $pkgid)
+        pkgtype=$(echo "$pkginfo" | grep "Type:" | awk -F ': ' '{print $2}')
+        preload=$(echo "$pkginfo" | grep "Preload:" | awk -F ': ' '{print $2}')
+        readonly=$(echo "$pkginfo" | grep "Readonly:" | awk -F ': ' '{print $2}')
+        options=""
+        if [[ $pkgtype == 'tpk' ]]; then
+          cmd='/usr/bin/tpk-backend'
+        elif [[ $pkgtype == 'wgt' ]]; then
+          cmd='/usr/bin/wgt-backend'
+        else
+          cmd='/usr/bin/unified-backend'
+        fi
+        if [[ $preload == "1" ]]; then
+          if [[ $readonly == "1" ]]; then
+            options="--preload"
           else
-            echo "$cmd is not installed"
-            exit 1
+            options="--preload-rw"
           fi
         fi
-      done
-    else
-      echo 'pkgmgr package is not installed in image, no preload packages'
-    fi
+        if [ -f $cmd ]; then
+          $cmd -d $pkg $options --force-remove
+        else
+          echo "$cmd is not installed"
+          exit 1
+        fi
+      fi
+    done
   else
-    echo 'rpm package is not installed in image'
-    exit 1
+    echo 'pkgmgr package is not installed in image, no preload packages'
   fi
 fi
 exit 0