1
0

280-call-prerm-and-postrm-scripts-on-upgrade.patch 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. From a8555d352d2851ee1482b74b57ba9eacfb354c18 Mon Sep 17 00:00:00 2001
  2. From: Peter Urbanec <peteru@urbanec.net>
  3. Date: Thu, 23 Oct 2014 01:05:35 +1100
  4. Subject: [PATCH] opkg_install: Call prerm and postrm scripts on package
  5. upgrade
  6. When upgrading a package from v1 to v2, run "v1-prerm upgrade v2" and
  7. "v1-postrm upgrade v2", similarly to what dpkg does.
  8. This patch fixes issue 104.
  9. Signed-off-by: Peter Urbanec <openembedded-devel@urbanec.net>
  10. Signed-off-by: Paul Barker <paul@paulbarker.me.uk>
  11. ---
  12. libopkg/opkg_install.c | 40 ++++++++++++++++++++++++++++++++++++++--
  13. 1 file changed, 38 insertions(+), 2 deletions(-)
  14. --- a/libopkg/opkg_install.c
  15. +++ b/libopkg/opkg_install.c
  16. @@ -528,7 +528,25 @@ prerm_upgrade_old_pkg(pkg_t *pkg, pkg_t
  17. Error unwind, for both the above cases:
  18. old-postinst abort-upgrade new-version
  19. */
  20. - return 0;
  21. + int err;
  22. + char *script_args;
  23. + char *new_version;
  24. +
  25. + if (!old_pkg || !pkg)
  26. + return 0;
  27. +
  28. + new_version = pkg_version_str_alloc(pkg);
  29. +
  30. + sprintf_alloc(&script_args, "upgrade %s", new_version);
  31. + free(new_version);
  32. + err = pkg_run_script(old_pkg, "prerm", script_args);
  33. + free(script_args);
  34. + if (err != 0) {
  35. + opkg_msg(ERROR, "prerm script for package \"%s\" failed\n",
  36. + old_pkg->name);
  37. + return -1;
  38. + }
  39. + return 0;
  40. }
  41. static int
  42. @@ -925,7 +943,25 @@ postrm_upgrade_old_pkg(pkg_t *pkg, pkg_t
  43. new-postrm failed-upgrade old-version
  44. Error unwind, for both cases:
  45. old-preinst abort-upgrade new-version */
  46. - return 0;
  47. + int err;
  48. + char *script_args;
  49. + char *new_version;
  50. +
  51. + if (!old_pkg || !pkg)
  52. + return 0;
  53. +
  54. + new_version = pkg_version_str_alloc(pkg);
  55. +
  56. + sprintf_alloc(&script_args, "upgrade %s", new_version);
  57. + free(new_version);
  58. + err = pkg_run_script(old_pkg, "postrm", script_args);
  59. + free(script_args);
  60. + if (err != 0) {
  61. + opkg_msg(ERROR, "postrm script for package \"%s\" failed\n",
  62. + old_pkg->name);
  63. + return -1;
  64. + }
  65. + return 0;
  66. }
  67. static int