libopkg: run prerm scripts for the old version also on upgrade
authorJo-Philipp Wich <jo@mein.io>
Fri, 10 Feb 2017 10:05:44 +0000 (11:05 +0100)
committerJo-Philipp Wich <jo@mein.io>
Fri, 10 Feb 2017 10:05:44 +0000 (11:05 +0100)
To make sure we properly restart services on upgrade we need to
call the prerm script of the old package, in case the init script
changes (or vanishes).

Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
Acked-by: Jo-Philipp Wich <jo@mein.io>
libopkg/opkg_install.c

index acb7530c863eabb90fa35464a5199fb92e5fba81..ad1169fd2228a19ece5088150c1e7eae5418937a 100644 (file)
@@ -528,7 +528,25 @@ prerm_upgrade_old_pkg(pkg_t *pkg, pkg_t *old_pkg)
           Error unwind, for both the above cases:
           old-postinst abort-upgrade new-version
      */
-     return 0;
+    int err;
+    char *script_args;
+    char *new_version;
+
+    if (!old_pkg || !pkg)
+        return 0;
+
+    new_version = pkg_version_str_alloc(pkg);
+
+    sprintf_alloc(&script_args, "upgrade %s", new_version);
+    free(new_version);
+    err = pkg_run_script(old_pkg, "prerm", script_args);
+    free(script_args);
+    if (err != 0) {
+        opkg_msg(ERROR, "prerm script for package \"%s\" failed\n",
+                 old_pkg->name);
+        return -1;
+    }
+    return 0;
 }
 
 static int
@@ -925,7 +943,25 @@ postrm_upgrade_old_pkg(pkg_t *pkg, pkg_t *old_pkg)
           new-postrm failed-upgrade old-version
        Error unwind, for both cases:
           old-preinst abort-upgrade new-version    */
-     return 0;
+    int err;
+    char *script_args;
+    char *new_version;
+
+    if (!old_pkg || !pkg)
+        return 0;
+
+    new_version = pkg_version_str_alloc(pkg);
+
+    sprintf_alloc(&script_args, "upgrade %s", new_version);
+    free(new_version);
+    err = pkg_run_script(old_pkg, "postrm", script_args);
+    free(script_args);
+    if (err != 0) {
+        opkg_msg(ERROR, "postrm script for package \"%s\" failed\n",
+                 old_pkg->name);
+        return -1;
+    }
+    return 0;
 }
 
 static int